I have 2 collections in my mongodb database: users
and posts
.
And in posts
collection I have DBRef field like this:
user : DBRef('users', ObjectId('...'), null)
When I'm going to remove some post by user id, I do the following:
db.posts.remove({ 'user.$id' : ObjectId('...') })
And it works great, but not from node-mongodb-native. From node-mongodb-native I'm getting following error while doing this request:
key must not contain '.'
Can anyoune see that? Thank you for your help and explanations if I'm wrong in something.
Update
find requests by DBRef $id work fine!
Node.js code:
var mongodb = require('mongodb')
, nconf = require('nconf')
, MongoClient = mongodb.MongoClient;
MongoClient.connect(nconf.get('db:connectionString'), function(mongoConnectionError, db) {
if (mongoConnectionError) throw mongoConnectionError;
db
.collection('posts')
.remove({ 'user.$id' : new mongodb.ObjectID('...') }, {}, function(err, removedItems) {
if (err) { throw err; }
console.log('Removed items: ' + removedItems);
});
});