简体   繁体   English

如何将结果mongoDB查询保存到数组或列表?

[英]How to save result mongoDB query to an array or list?

My query 我的查询

test.find({ "age" : "20" }, {"email": 1, "_id": 0}).toArray(function (err,data) {
          if (err) throw err;
          console.log(data);

and result after I run my query 和运行查询后的结果

[ { email: 'root@root.com' } ]

How can I save console.log(data); 如何保存console.log(data); to an Array or list ? 到数组或列表? I tried .push(data) to save but not ok. 我尝试保存.push(data) ,但不行。

Create an empty object and then assign value to it 创建一个空对象,然后为其分配值

test.find({ "age" : "20" }, {"email": 1, "_id": 0}).toArray(function (err,data) {
      if (err) throw err;
      console.log(data);
var obj =[];
var obj = data;

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

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