MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Node js Mongodb Query NumberLong

Questo funziona bene per me, forse la tua richiesta non viene emessa correttamente. Considera i seguenti dati e codice come esempio da confrontare:

> db.test.find()
{ 
    "_id" : ObjectId("5303f24423d2721c25c493ee"), 
    "ts" : NumberLong("635186135151387725") 
}
{ 
    "_id" : ObjectId("5303f24a23d2721c25c493ef"), 
    "ts" : NumberLong("635186135151387726") 
}
>

E il codice da trovare:

var MongoClient = require('mongodb').MongoClient;

var Long = require('mongodb').Long;

MongoClient.connect('mongodb://localhost/test', function(err, db) {

    var collection = db.collection('test');

    var value = Long.fromString("635186135151387726");

    console.log( value );

    var cursor = collection.find({ ts: {"$gte": value} });

    cursor.toArray(function(err, items) {
        console.log( items );
    });

});

Fornisce l'output come previsto:

{ _bsontype: 'Long', low_: -1342987186, high_: 147890796 }
[ { _id: 5303f24a23d2721c25c493ef,
    ts: { _bsontype: 'Long', low_: -1342987186, high_: 147890796 } } ]