使用mongoose在mongo中查找用户,并将结果返回给JSON [英] Find user in mongo, with mongoose, and return the result to a JSON
本文介绍了使用mongoose在mongo中查找用户,并将结果返回给JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在mongo中搜索某些用户并将其放入json中,但是每次尝试使用时,得到的结果都是带有元数据的大对象.
I want to search in mongo some user and put them in a json, but everytime I tried it the result that I got is a big object with metadata.
以下代码包含我所做的事情
The following code contains what I've done
var myJson = {
user : User.findOne({
firstName: regex,
lastName: authorSplitedName.last
}, function (err, user){
return user;
})
}
非常感谢您的帮助!
推荐答案
尝试使用 JSON.stringify()删除猫鼬对象属性:
Try using JSON.parse() and JSON.stringify() to remove mongoose object property:
var myJson = {
user : User.findOne({
firstName: regex,
lastName: authorSplitedName.last
}, function (err, user){
return JSON.parse(JSON.stringify(user)));
})
}
这篇关于使用mongoose在mongo中查找用户,并将结果返回给JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文