mongodb - Mongo. how to check if field is a number -
how select mongodb documents field number?
some examples of content of field: "2", "a", "z", 3
you can use $type operator select based on bson type of field, should want.
so, example, find strings:
db.collection.find( { field: { $type : 2 } } )
or, find doubles (which numbers stored shell default javascript behavior), use:
db.collection.find( { field: { $type : 1 } } )
since there 2 types of integer (potentially) need go this:
db.collection.find({$or : [{"field" : { $type : 16 }}, {"field" : { $type : 18 }}]})
finally then, numbers, integer or double:
db.collection.find({$or : [{"field" : { $type : 1 }}, {"field" : { $type : 16 }}, {"field" : { $type : 18 }}]})
Comments
Post a Comment