Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update issue #164

Open
mike-aungsan opened this issue May 1, 2015 · 3 comments
Open

update issue #164

mike-aungsan opened this issue May 1, 2015 · 3 comments

Comments

@mike-aungsan
Copy link

The following code does not work. Any bugs or anything wrong?

For sure ids are in the db. But it does not update at all.

var idsObj = [];
var ids = [ 1426879378856, 1426878899305, 1426878875930 ];

_.each(ids, function (id) {
idsObj.push({'_id': new objectID(id._id)});
});

var findQuery = {'$or': idsObj};

db.collection('bands').update(findQuery, {'$set': {updateThis: 'blur blur'}},
{w:"majority", wtimeout:500, j:true, remove:true, upsert:false, multi:t},
function(err, result) {
if (err) {
console.log(err);
}
else {
console.log(result);
}
});

If I run this in the shell, it update all 3 docs.

db.collection('bands').update({$or: [{'_id': ObjectId('550c7393e50a63c0d712d25e')},
{'_id': ObjectId('550c71b4e50a63c0d712d25d')},
{'_id': ObjectId('550c7196e50a63c0d712d25c')}] },
{$set : {updateThis: 'blur blur' } },
{w:"majority", wtimeout:500, j:true, remove:true, upsert:false, multi:true}
)

@vkarpov15
Copy link
Contributor

Correct me if I'm wrong, but id._id is undefined in your code - numbers don't have an _id field...

@mike-aungsan
Copy link
Author

Sorry typo. It should be like this

var idsObj = [];
var ids = [ 1426879378856, 1426878899305, 1426878875930 ];

_.each(ids, function (id) {
idsObj.push({'_id': new objectID(id)})
});

@vkarpov15
Copy link
Contributor

So when you pass a number to an ObjectId, ObjectId treats it as a timestamp. However, an ObjectId is not uniquely defined by a timestamp. Any reason why you're not just passing in the hex string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants