Node MongoDB 组件是用 insert 插入数据吗
发布于 10 年前 作者 lioff 3711 次浏览 最后一次编辑是 8 年前
mongodb.open(function (err,collection) {
    if(err) {
        mongodb.close();
        return callback(err);    
    }  
    // 这里 collection.insert 方法不存在 我打印了一下 collection 有毛线insert啊 
    collection.insert(user,{safe:true}, function(err, user) {
        mongodb.close();
        callback(err, user);
    });

///   mongodb 的定义
var settings = require("../settings.js");
var Md = require("mongodb")
var Db = Md.Db;
var Connection = Md.Connection;
var Server = Md.Server;
module.exports = new Db(settings.db, new Server(settings.host, Connection.DEFAULT_PORT,{}));



//// collection打印出来的方法 部分 
domain
_events
_maxListeners
databaseName
serverConfig
options
_applicationClosed
slaveOk
bufferMaxEntries
native_parser
bsonLib
bson
bson_deserializer
bson_serializer
_state
pkFactory
forceServerObjectId
safe
notReplied
isInitializing
openCalled
commands
logger
tag
eventHandlers
serializeFunctions
raw
recordQueryStats
retryMiliSeconds
numberOfRetries
readPreference
open
db
close
admin
collectionsInfo
collectionNames
collection
collections
eval
dereference
logout
3 回复

为什么不去看看mongodb-native 官方 的文档啊,例子满大街是,偏偏要自己在这里瞎琢磨

是啊,首先要学会查资料!

@stepjacky上面那段代码呢 也不是我自己瞎琢磨出来的,我也是看的例子,已经解决了。麻烦你以后不回答问题就不要作点评,什么查文档,自己百度,这些东西显得你我都很没文化。

回到顶部