从String形成mongo查询

时间:2015-03-11 16:24:45

标签: node.js mongodb npm

我正在使用mongo-parse来解析mongo查询。以下是我的代码

var parser = require('mongo-parse')
var queryObject = parser.parse({"city":"Paris"})
//Getting field and value separately
//Field = city
//Value = Paris

var string = 'db.employee.find({"city":"Paris"},{"emp_id":1}'
//Not able to get the field and value separately from string

是否有任何节点模块可以从上面的字符串生成mongo查询。

对此的任何帮助都会非常有用

1 个答案:

答案 0 :(得分:0)

它看起来不像mongo-parse返回有关该集合的任何信息。考虑到这一点,你不能只是从解析器中获取分析并从数据中手工构建查询(假设我正确理解你的问题)

e.g。

var newQuery = {};
newQuery[queryObject.field] = queryObject.value;
db.employee.find(newQuery, {emp_id: 1});
相关问题