Is it possible to cast in a MongoDB-Query?

前端 未结 5 1307
醉梦人生
醉梦人生 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:49

    I have a similar workaround, i find that if you can use the mongo shell, you can write an statement to do this in javascript, but capable of using indexes.

    var myItems = []
    var it = db.test.find({},{value:1})
    while (it.hasNext()){
     var item = it.next();
     if(parseInt(item.value) > 12)
      myItems.push(item);
    }
    

    If you want this to run faster than previus solution, you have to ensure the index on the value field.

提交回复
热议问题