dongmei3498 2015-11-02 05:57
浏览 159

Mongodb按指定的ID数组排序和获取记录

Hi I am looking for solution. I am not sure if this question is already here in stackoverflow. I was trying to find its solution on google but couldn't find any solution. I need to fetch records from mongo database such that it should be ordered by the array of ids I specify only. For example following is the set of data from the required table.

{ "_id" : NumberLong("5832686213760"), "created_by" : "3694181860160", "title" : "adsf", "date" : "2015-10-12 21:57:27", "cat" : "251", "description" : "dsafadsf", "members" : [ "3694181860160" ], "battles" : [ ], "is_deleted" : NumberLong(0) }

{ "_id" : NumberLong("5836854817600"), "created_by" : "3692778550272", "title" : "dd", "date" : "2015-10-13 02:13:32", "cat" : "939", "description" : "dddd", "members" : [ "3692778550272", "3690476217152" ], "battles" : [ "1475499726016" ], "is_deleted" : NumberLong(0) }

{ "_id" : NumberLong("5830033945536"), "created_by" : "3692705624256", "title" : "My own group", "date" : "2015-10-11 11:50:27", "cat" : "731", "description" : "yes this is my own group. hahahhahah", "members" : [ "3692705624256" ], "battles" : [ "1478264481792", "1472313521152", "1478428020992" ], "is_deleted" : NumberLong(0) }

If I need to fetch the above data in the order as following array specify.

array("5830033945536","5832686213760", "5836854817600")

Please note that this is only a part of data and ids, the real query will be dynamic. I am working in Yii 1.x. So I need the solution in json as well as in php.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 有人会搭建GPT-J-6B框架吗?有偿
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名