Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务器上Meteor中的mongodb distinct()实现?_Mongodb_Meteor - Fatal编程技术网

服务器上Meteor中的mongodb distinct()实现?

服务器上Meteor中的mongodb distinct()实现?,mongodb,meteor,Mongodb,Meteor,我需要在Meteor中从mongodb获取不同的值(基本上,实现mongodb本机distinct()调用)。在客户端,-这就像一个魅力。但我不知道如何在服务器端获得类似的工作。谢谢你的帮助。谢谢 在深入研究代码并实现mongo lib包含我从中重用的aggregate()解决方案所需的所有方法的本机实现后,确定 对coffeescript进行简单的更改和翻译,可以将以下代码片段放入服务器端代码中: path = __meteor_bootstrap__.require("path") Mong

我需要在Meteor中从mongodb获取不同的值(基本上,实现mongodb本机distinct()调用)。在客户端,-这就像一个魅力。但我不知道如何在服务器端获得类似的工作。谢谢你的帮助。谢谢

在深入研究代码并实现mongo lib包含我从中重用的aggregate()解决方案所需的所有方法的本机实现后,确定

对coffeescript进行简单的更改和翻译,可以将以下代码片段放入服务器端代码中:

path = __meteor_bootstrap__.require("path")
MongoDB = __meteor_bootstrap__.require("mongodb")
Future = __meteor_bootstrap__.require(path.join("fibers", "future"))

myCollection = new Meteor.Collection "my_collection"

#hacky distinct() definition from https://github.com/meteor/meteor/pull/644
myCollection.distinct = (key)->
  future = new Future
  @find()._mongo.db.createCollection(@_name,(err,collection)=>
    future.throw err if err
    collection.distinct(key, (err,result)=>
      future.throw(err) if err
      future.ret([true,result])
      )
    )
  result = future.wait()
  throw result[1] if !result[0]
  result[1]
缺点是你必须为每一个新的集合定义它,但这很简单,可以通过u.extend或其他我想是的东西来修复


PS它现在也是一个智能包-
mrt添加mongodb聚合

在对代码进行深入研究并实现mongo lib包含我从中重用的aggregate()解决方案所需的所有方法的本机实现后,Ok

对coffeescript进行简单的更改和翻译,可以将以下代码片段放入服务器端代码中:

path = __meteor_bootstrap__.require("path")
MongoDB = __meteor_bootstrap__.require("mongodb")
Future = __meteor_bootstrap__.require(path.join("fibers", "future"))

myCollection = new Meteor.Collection "my_collection"

#hacky distinct() definition from https://github.com/meteor/meteor/pull/644
myCollection.distinct = (key)->
  future = new Future
  @find()._mongo.db.createCollection(@_name,(err,collection)=>
    future.throw err if err
    collection.distinct(key, (err,result)=>
      future.throw(err) if err
      future.ret([true,result])
      )
    )
  result = future.wait()
  throw result[1] if !result[0]
  result[1]
缺点是你必须为每一个新的集合定义它,但这很简单,可以通过u.extend或其他我想是的东西来修复


PS它现在也是一个智能包-
mrt添加mongodb聚合

如果有人在Meteor v1.0+(1.0.2)中尝试此功能,此代码对我有效,我将其放在服务器上。基本上与何俊杰的答案相同,只是提到了一些调整——Npm.require,以及未来['return']。为外面的咖啡编剧清理了一下

我正在考虑这个包,但是已经有了
meteohacks:aggregate
包(仅
aggregate
函数),因此我不想冒险用另一个包覆盖它。所以,我只是在其他人的帮助下推出了自己的
与众不同的

希望这对别人有帮助!最有可能的是,如果我继续在更多集合上使用distinct,我将使用
。.extend Meteor.Collection
如下所示:
https://github.com/zvictor/meteor-mongo-server/blob/master/server.coffee

path = Npm.require('path')
Future = Npm.require(path.join('fibers', 'future'))

myCollection = new Meteor.Collection "my_collection"

myCollection.distinct = (key, query) ->
  future = new Future
  @find()._mongo.db.createCollection @_name, (err,collection) =>
    future.throw err if err

    collection.distinct key, query, (err,result) =>
      future.throw(err) if err
      future['return']([true,result]) 

  result = future.wait()
  throw result[1] if !result[0]
  result[1]

如果有人在Meteor v1.0+(1.0.2)中尝试这一点,这段代码对我有效,我将它放在服务器上。基本上与何俊杰的答案相同,只是提到了一些调整——Npm.require,以及未来['return']。为外面的咖啡编剧清理了一下

我正在考虑这个包,但是已经有了
meteohacks:aggregate
包(仅
aggregate
函数),因此我不想冒险用另一个包覆盖它。所以,我只是在其他人的帮助下推出了自己的
与众不同的

希望这对别人有帮助!最有可能的是,如果我继续在更多集合上使用distinct,我将使用
。.extend Meteor.Collection
如下所示:
https://github.com/zvictor/meteor-mongo-server/blob/master/server.coffee

path = Npm.require('path')
Future = Npm.require(path.join('fibers', 'future'))

myCollection = new Meteor.Collection "my_collection"

myCollection.distinct = (key, query) ->
  future = new Future
  @find()._mongo.db.createCollection @_name, (err,collection) =>
    future.throw err if err

    collection.distinct key, query, (err,result) =>
      future.throw(err) if err
      future['return']([true,result]) 

  result = future.wait()
  throw result[1] if !result[0]
  result[1]

可能的复制品不是,至少不是全部,我和那个有联系。很明显,它只在客户机上起作用。它的可能副本不是,至少不是全部,我和那个链接。它显然只在客户端上起作用。我正在使用meteor 0.8.2,必须进行以下替换才能使用此代码meteor\u bootstrap=>Npm,future.ret=>future.ret。要求mongodb似乎没有必要。我本来会使用这个软件包,但是它不支持用户身份验证,从而使基础集合完全打开。我使用的是meteor 0.8.2,必须进行以下替换才能使用此代码meteor_bootstrap=>Npm,future.ret=>future.ret。要求mongodb似乎没有必要。我本来会使用这个包,但是它缺乏对用户身份验证的支持,使得底层集合完全开放。