sergeyksv / tingodb

Embedded Node.js database upward compatible with MongoDB
www.tingodb.com
1.16k stars 105 forks source link

$pull doesn't seem to work on an embedded collection #149

Closed mably closed 7 years ago

mably commented 7 years ago

Here is my code, I'm trying to implement two-phase commit from MongoDb documentation :

accountsCollection.update(
    { _id: id, pendingTransactions: txid },
    { $pull: { pendingTransactions: txid } },
    { w: 1 }, function (err, result) {
        // some code
    }
);

It looks like $pull doesn't work on my side, the txid is never removed from the pendingTransactions collection.

Am I doing something wrong?

Thanx for your help.

EDIT: it looks like the problem is with the pendingTransactions: txid part of the query selector, don't know why though. Is it possible to filter an update by a collection field value?

mably commented 7 years ago

Looks like the problem is rather related to my array field query filter and not $pull. Closing.

Found some help here: https://github.com/sergeyksv/tingodb/issues/135

One solution is to enable search in array globally with:

var Db = require('tingodb')( {searchInArray:true}).Db.

Though it still doens't seem to work with _id values, had to convert them to string using _id + ''