node.js mongodb通过_id node-mongodb-native选择文档 [英] node.js mongodb select document by _id node-mongodb-native

查看:150
本文介绍了node.js mongodb通过_id node-mongodb-native选择文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按ID选择文件

I'm trying to select a document by id

我尝试过:

collection.update({ "_id": { "$oid": + theidID } }

collection.update({ "_id": theidID }

collection.update({ "_id.$oid": theidID }}

同时尝试:

collection.update({ _id: new ObjectID(theidID ) }

这给我一个错误500 ...

This gives me an error 500...

var mongo = require('mongodb')
var BSON = mongo.BSONPure;
var o_id = new BSON.ObjectID(theidID );

collection.update({ _id: o_id }

这些都不起作用。如何通过_id选择?

None of these work. How to select by _id?

推荐答案

var mongo = require('mongodb');
var o_id = new mongo.ObjectID(theidID);
collection.update({'_id': o_id});

这篇关于node.js mongodb通过_id node-mongodb-native选择文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆