简体   繁体   English

$ 大括号内

[英]$ inside curly brackets

I am going through a tutorial, and the author has written a line of code in a GET response through a query string.我正在学习一个教程,作者通过查询字符串在 GET 响应中编写了一行代码。 They write the $ inside the curly brackets without any backticks.他们将 $ 写在大括号内,没有任何反引号。

Here is the line of code:这是代码行:

Product.find({ '_id':{$in:items}}).exec({err,docs}=>{ return res.status(200).send(docs) })

I have no idea what exactly is happening.我不知道到底发生了什么。

$ is a valid character in variable names. $是变量名中的有效字符。 Eg例如

let x = 5;
let $ = 6;
let x$8_$$ = 7;
let obj = {$: 8, $$$__$sf93$: 9};

In your snippet, they're using $in as the key in an object literal.在您的代码段中,他们使用$in作为对象文字中的键。 Ie, let's say items = [1,2,3] , then the param to Product.find is {'_id': {'$in': [1, 2, 3]}} .即,假设items = [1,2,3] ,那么Product.find的参数是{'_id': {'$in': [1, 2, 3]}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM