I am doing the learnyoumongo tutorials to learn mongoDB.
On the third excercise (the find tutorial) I couldn't get it to work until i just found the solution. My mistake was that the query needed a "+" in front of the argument.
so db.coll.find({ $gt: process.argv[2] })
did not work, but { $gt: +process.argv[2] }
did.
Perhaps this is a stupid question, but what is that plus sign, and when would I use it?
Also does it play a role in regular javascript?
The +
in this context is an implicit cast to a number. process.argv[2]
will be a string. The +
is simply a quick, easy, and generally safe way to cast it to a number. $gt
expects a number for comparison rather than a string -- even a numeric string.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加