mongodb关联查询----js

说明

只是记录下,做个笔记。

集合

有两个集合:gg_mfratiostock

gg_mfratio集合数据:

这里写图片描述

stock集合数据:
这里写图片描述

其中:

db.gg_mfratio.find({"reportdate" : ISODate("2016-12-31T00:00:00.000+08:00")})

执行后是总共36条数据。
也就是说我想验证这36条数据是否都关联到stock中。

可以执行下面这条语句:

db.gg_mfratio.find({"reportdate" : ISODate("2016-12-31T00:00:00.000+08:00")},{publishdate:1,reportdate:1,companycode:1}).forEach(
    function(o){   
    var val = db.stock.find({companycode:o.companycode})
    //print(val)
    val.forEach(function(y){
        print(y.stock_name + "/" + y.stock_code)
        //print(y)
        })
    })

结果:

这里写图片描述

注意:由于在mongodb中使用js的形式会很慢,所以在代码中最好不要去写,建议用于数据验证,用以验证代码是否正确。

Mingo 是 MongoDB 查询语言的 JavaScript 实现。Mingo 利用 MongoDB 风格查询,在客户端或者服务器端环境下,允许直接查询内存的 JavaScript 对象。特性:Comparisons Operators ($gt, $gte, $lt, $lte, $ne, $nin, $in)Logical Operators ($and, $or, $nor, $not)Evaluation Operators ($regex, $mod, $where)Array Operators ($all, $elemMatch, $size)Element Operators ($exists, $type)Aggregation Pipeline Operators ($group, $match, $project, $sort, $limit, $unwind, $skip)Conditional Operators ($cond, $ifNull)Group Operators ($addToSet, $sum, $max, $min, $avg, $push, $first, $last)Arithmetic Operators ($add, $divide, $mod, $multiply, $subtract)String Operators ($cmp, $strcasecmp, $concat, $substr, $toLower, $toUpper)Set Operators ($setEquals, $setIntersection, $setDifference, $setUnion, $setIsSubset, $anyElementTrue, $allElementsTrue)Projection Operators ($elemMatch, $slice)JSON stream filtering and projection. NodeJS only使用var Mingo = require('mingo'); // or just access *Mingo* global in browser // setup the key field for your collection Mingo.setup({     key: '_id' // default }); // create a query with criteria // find all grades for homework with score >= 50 var query = new Mingo.Query({     type: "homework",     score: { $gte: 50 } });搜索和过滤// filter collection with find() var cursor = query.find(collection); // shorthand with query criteria // cursor = Mingo.find(collection, criteria); // sort, skip and limit by chaining cursor.sort({student_id: 1, score: -1})     .skip(100)     .limit(100); // count matches cursor.count(); // iterate cursor // iteration is forward only while (cursor.hasNext()) {     console.log(cursor.next()); } // use first(), last() and all() to retrieve matched objects cursor.first(); cursor.last(); cursor.all(); // Filter non-matched objects ( var result = query.remove(collection); 标签:Mingo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山鬼谣me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值