Is it possible to cast in a MongoDB-Query?

前端 未结 5 1298
醉梦人生
醉梦人生 2020-12-01 18:13

When I have two MongoDB documents like this...

db.test.insert( {\"value\" : \"10123\"} );
db.test.insert( {\"value\" : \"160\"} );

The resu

5条回答
  •  暖寄归人
    2020-12-01 18:39

    To convert String into int use this

    db.test.find({'year': {$type: 2}}).forEach(
        function (x) {
            x.value=new NumberInt(x.value); 
            db.test.save(x)}
        )
    

    And after that you can directly query like :

    db.test.find({"value" :{$gt : 12} });
    

提交回复
热议问题