比方说,我有一个蒙戈集合与text index在itemName这些3个文件字段:
{
_id: ...,
itemName: 'Mashed carrots with big carrot pieces',
price: 1.29
},
{
_id: ...,
itemName: 'Carrot juice',
price: 0.79
},
{
_id: ...,
itemName: 'Apple juice',
price: 1.49
}
Run Code Online (Sandbox Code Playgroud)
然后我执行一个这样的查询:
db.items.find({ $text: { $search: 'Car' } }, { score: { $meta: "textScore" } }).sort( { score: { $meta: "textScore" } } );
Run Code Online (Sandbox Code Playgroud)
在返回字符串中某处包含"Car"的任何其他文档之前,如何强制mongo 返回以"Car"开头的文档(不区分大小写)?itemName
所以我想按以下顺序检索文档:
[
{..., itemName: 'Carrot Juice', ...},
{..., itemName: 'Mashed carrots with big …Run Code Online (Sandbox Code Playgroud) 所以我想连接到我的主机上运行的mongodb(DO droplet,Ubuntu 16.04).它27017在localhost 上的默认端口上运行.
然后我使用mup在我的DO droplet上部署我的Meteor应用程序,它使用docker在容器内运行我的Meteor应用程序.到现在为止还挺好.标准mongodb://...连接URL用于将应用程序连接到mongodb.现在我有以下问题:
mongodb://...@localhost:27017...显然在docker容器内不起作用,因为localhost它不是主机的localhost.
我已经在这上面阅读了很多stackoverflow帖子,我已经尝试过使用:
--network="host"- 没有工作,因为它0.0.0.0:80已经在使用或类似的东西(nginx代理)--add-host="local:<MY-DROPLET-INTERNET-IP>"和连接通过mongodb://...@local:27017...:也没有工作,因为我只能从localhost访问我的mongodb,而不是从公共IP这必须是一个常见的问题!
tl; dr - localhost在docker容器中公开主机的正确方法是什么,以便我可以连接到主机上运行的服务?(包括他们的港口,例如27017).
我希望有人能帮帮忙!
我正在使用以下模型在我的jQuery代码中执行AJAX请求时显示我的加载微调器:
jQuery.ajaxSetup({
beforeSend: function() {
$('#loader').show()
},
complete: function(){
$('#loader').hide()
},
success: function() {
$('#loader').hide()
}
});
Run Code Online (Sandbox Code Playgroud)
这段代码对我来说非常好!
只有一个问题:
有些请求非常简单快速,因此加载微调器只显示了几毫秒.那当然不是很漂亮.
所以我尝试使用setTimeout()稍微延迟显示加载微调器.我希望它只在AJAX请求至少占用时弹出,比方说100ms,但它不起作用.
所以我需要一些代码来延迟加载微调器,正如我上面解释的那样,因此它只会在执行"更长"的AJAX请求时弹出!
这是我旧问题的新版本:
所以,多亏Tom Coleman的帮助,我终于想出了如何正确检查订阅是否准备就绪().
我目前的代码结构如下所示:
/client/app.js:
eventsHandle = null;
groupsHandle = null;
// ...
// First Deps.autorun():
// Does not depend on any Session var, should just run every time
Deps.autorun(function() {
eventsHandle = Meteor.subscribe("events", function() {
console.log('Deps.autorun(): Events loaded');
});
});
// Second Deps.autorun():
// contains all subscriptions which are dependent on my Session var "ehash"
Deps.autorun(function() {
if(Session.get('ehash'))
groupsHandle = Meteor.subscribe("groups", Session.get('ehash'), function() {
console.log('Deps.autorun(): Groups loaded with ehash: ' + Session.get('ehash'));
});
});
// ...
Run Code Online (Sandbox Code Playgroud)
然后我查看了名为的文件夹中所有模板内容的特定.js和.html文件: …
因此,我尝试在查询中“加入” 3个不同的mongo集合。所以我需要的是mongo聚合中的Multiple $lookup和$groupStatement。
我的3个收藏集如下所示:
用户:(伪代码)
{
_id,
username: String,
group: <some group._id>
}
Run Code Online (Sandbox Code Playgroud)
组:
{
_id,
name: String,
_parent: <another group._id>,
}
Run Code Online (Sandbox Code Playgroud)
列表:(这些是由用户拥有的“ itemlists”):
{
_id,
name: String,
userId: <some user._id>
}
Run Code Online (Sandbox Code Playgroud)
因此,我想做的是,给定一些组ID或null(对于没有父级的组-最高级别的组)-获得groups该组的全部内容,找到users这些组及其所有内容lists。
所以最后我需要这样的东西:
[
{
_id: someGroupId,
name: someGroupName,
type: "group",
users: [
{
_id: someUserId,
name: someUserName,
type: "user",
lists: [
... and the same again for the lists (type: "list")
]
},
... another …Run Code Online (Sandbox Code Playgroud) mongodb ×3
ajax ×1
collections ×1
containers ×1
docker ×1
indexing ×1
javascript ×1
jquery ×1
meteor ×1
networking ×1
node.js ×1
reverse-ajax ×1
server-push ×1
socket.io ×1