> db.foo.find({"extraid": 123})
{ "_id" : ObjectId("5e4e3e068438c24cdec0eeb9"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eeba"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc", "efg" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebc"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123 ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebd"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebd"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
> db.foo.find({"extraid": {"$eq": 123}})
{ "_id" : ObjectId("5e4e3e068438c24cdec0eeb9"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eeba"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc", "efg" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebc"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123 ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebd"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
$type
operator so that it can match exactly, but the result is still not I want:> db.foo.find({"extraid": {"$eq": 123, "$type":"int"}})
{ "_id" : ObjectId("5e4e3e068438c24cdec0eeb9"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eeba"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc", "efg" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebc"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123 ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebd"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
> db.foo.find({"extraid": {"$eq": 123, "$type":"array"}})
{ "_id" : ObjectId("5e4e3e068438c24cdec0eeb9"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eeba"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123, "abc", "efg" ] }
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebc"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : [ 123 ] }
>
$type: array
can match all array type of 'extraid', but $type: int
is not work.--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/5ced83da-ff00-475d-baa0-f4824d4eaace%40googlegroups.com.
db.foo.find( { $expr: { $eq: [ { $type: "$extraid" }, "double" ] } } )
db.foo.aggregate( [
{ $addFields: { fld_type: { $type: "$extraid" } } }
] ).pretty()
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebd"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
To unsubscribe from this group and stop receiving emails from it, send an email to mongod...@googlegroups.com.
> db.bar.find( { $expr: {$and: [{ $eq: [ { $type: "$extraid" }, "int"] }, { $eq: ["$extraid", 123] }]} } )
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebd"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
>
Hello,
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/71deb34f-7ed4-40a9-b3f4-733a2d411aa6%40googlegroups.com.
> db.foo.find({$and:[{"extraid":{$not:{$type:"array"}}},{"extraid": 123}]})
{ "_id" : ObjectId("5e4e3e078438c24cdec0eebd"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
>
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/71deb34f-7ed4-40a9-b3f4-733a2d411aa6%40googlegroups.com.
> db.bar.find( { $expr: {$and: [{ $eq: [ { $type: "$extraid" }, "number"] }, { $eq: ["$extraid", 123] }]} } )
> db.bar.find( { $expr: {$and: [{ $eq: [ { $type: "$extraid" }, "int"] }, { $eq: ["$extraid", 123] }]} } )
{ "_id" : ObjectId("5e4f97aceb649645a42d7918"), "from" : "0xabsdfeeqwsfdasfafaefegr", "to" : "0xfdshshrtfafdfadfaete", "extraid" : 123 }
Hello,
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/32760905-c709-4e1e-8dff-849d34dfffd6%40googlegroups.com.