bson_serializer未定义

时间:2015-10-28 15:08:36

标签: javascript node.js mongodb bson

我开始玩'与mongodb有一些问题我仍然无法弄清楚如何解决它们。

给出以下代码(取自book):

var mongodb = require('mongodb');
var server = new mongodb.Server('127.0.0.1', 27017, {});

var client = new mongodb.Db('mydatabase', server, {w: 1});
var tmpID = '';

client.open(function(err){
    if(err) throw err;
    client.collection('test_insert', function(err, collection){
        if(err) throw err;
        console.log('we are now able to perform queries.');
        collection.insert(
            {
                "title": "I like cake",
                "body": "It is quite good."
            },  
            {safe: true},
            function(err, documents){
                if(err) throw err;
                tmpID = documents.ops[0]._id;               
                console.log('Document ID is: ' + tmpID);
                var _id = new client.bson_serializer.ObjectID(tmpID.toString()); 
                collection.update(
                    {_id: _id},
                    {$set: {"title": "I ate too much cake"}},
                    {safe:true},
                    function(err){
                        if (err) throw err;
                    }
                );
            }
        );
    });
});

我希望文件的标题是"我喜欢蛋糕"得到更新。我在这一行得到例外:

var _id = new client.bson_serializer.ObjectID(tmpID);

TypeError: Cannot read property 'ObjectID' of undefined

我检查了client对象,我看不到bson_serializer ......

  

nodejs 4.2.1

     

MondoDB 3.0

相关问题: https://stackoverflow.com/questions/33111123/node-js-mondodb-2-driver-bson-serializer-error-after-updating-mongolab-free-sand

0 个答案:

没有答案