このような 2 つの MongoDB ドキュメントがある場合...
db.test.insert( {"value" : "10123"} );
db.test.insert( {"value" : "160"} );
次のようなクエリの結果:
db.test.find({"value" :{$gt : "12"} });
は..
{ "_id" : ObjectId("4c6d1b92304326161b678b89"), "value" : "160" }
最初の値が返されないように、文字列の比較が行われることは明らかです。クエリ内でキャストする方法はありますか?
何かのようなもの:
db.test.find({ (int) "value" :{$gt : 12} });
素晴らしいことだ。のようなクエリ
db.test.find({"value" :{$gt : 12} }); // without the quotes around "12"
何も返しません。