Tag: mongodb

如何防止从Mongodb中自动删除收集logging

你好,我被困在某个地方,我正在与node.js mongodb工作,我的collections数据在一定的date1年后自动删除,我想永久停止,我怎么能做到这一点? 我已经检查了谷歌的可用材料,但没有得到太多的成功,请帮助我的朋友… 我已经检查了我的一个collections中的索引,它显示的是这样的数据。 你能告诉我它有TTL索引吗? [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "firstfive.teachers" }, { "v" : 1, "key" : { "_fts" : "text", "_ftsx" : 1 }, "name" : "firstname_lastname_text", "weights" : { "firstName" : 1, "lastName" : 1 }, "default_language" : "english", "language_override" […]

如何将1个mongoDB集合分成2个或更多的集合

我使用mongoDB来使用Node.js来取消数据集。 我收集了20万份文档,所以Node.js崩溃了,出现了分段错误。 有没有办法将集合拆分/分割成2个或更多集合,以便Node.js不会崩溃。 谢谢!!

查询MongoDB嵌套字段

编辑 我现在已经意识到会话文档有一个FIELD session和一个VALUE值。 所以cookie: { passport: { user:… } } }不是嵌套对象,它们都只是一个大string。 所以,现在我可以使用$正则expression式查询来find我需要的: Session.find({ 'session': {$regex : ".*jane@gmail.com.*"} }, function(error, session){ =========原来的问题========== 我正在使用connect-mongo将用户的会话保存到MongoDB,我想查询session集合以查明用户是否有活动的会话。 用户名存储在sessions.cookie.passport.user下的集合中,但是我的查询返回空。 以下是一个会话文档示例: { "_id": "orxJPolqKQ11rZdYhTKMuS90G-zDrrKk", "session": "{ \"cookie\":{ \"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"}, \"flash\":{}, \"passport\":{ \"user\":\"jane@email.com\" // <- This is what I want! } // … More info here… 我到目前为止试过的查询: Session.find({ "session.cookie.passport.user": "jane@gmail.com" }, function(error, session){ 和, […]

Mongoose $不在nodeJS中工作

我创build了一个包含如下所示的一些操作细节的集合 { "_id" : ObjectId("580776455ecd3b4352705ec4"), "operation_number" : 10, "operation_description" : "SHEARING", "machine" : "GAS CUTT" } { "_id" : ObjectId("580776455ecd3b4352705ec5"), "operation_number" : 50, "operation_description" : "EYE ROLLING -1", "machine" : "E-ROLL-1" } { "_id" : ObjectId("580776455ecd3b4352705ec6"), "operation_number" : 60, "operation_description" : "EYE ROLLING -2", "machine" : "E-ROLL-1" } { "_id" : ObjectId("580776455ecd3b4352705ec7"), "operation_number" : 70, […]

如何通过mongoose中的子文档字段对logging进行分组?

假设我们有以下数据 *家长* { _id: 10, child: ObjectID(20) } { _id: 11, child: ObjectID(21) } { _id: 12, child: ObjectID(23) } *儿童* { _id: 20, name: 'test-1' } { _id: 21, name: 'test-2' } { _id: 22, name: 'test-3' } { _id: 23, name: 'test-1' } 我想知道用什么mongoose得到下面的结果。 { _id: 'test-1', count: 2} { _id: 'test-2', count: […]

mongoose:“投入embedded失败的价值在path。 不能使用'in'运算符search'_id'

我尝试在一个对象数组中保存一个数组时遇到了一些麻烦。 我收到服务器的以下响应: { [CastError: Cast to embedded failed for value "\'maxbeds: 4\'" at path "saved_searches"] message: 'Cast to embedded failed for value "\\\'maxbeds: 4\\\'" at path "saved_searches"', name: 'CastError', kind: 'embedded', value: '\'maxbeds: 4\'', path: 'saved_searches', reason: [TypeError: Cannot use 'in' operator to search for '_id' in maxbeds: 4] } 这是我的模式: var mongoose = require('mongoose'), […]

如何获取用户authservicelogin的currenlty的用户名

我想获得当前用户名,以便我可以显示它。 但我不知道该怎么做? 有任何想法吗 ? 我正在使用authservice这里是我的angular度控制器,我想获得用户名。 myApp.controller('meetupsController', ['$scope', '$resource', function ($scope, $resource) { var Meetup = $resource('/api/meetups'); $scope.meetups = [] Meetup.query(function (results) { $scope.meetups = results; }); $scope.createMeetup = function () { var meetup = new Meetup(); meetup.name = $scope.meetupName; meetup.$save(function (result) { $scope.meetups.push(result); $scope.meetupName = ''; }); } }]); 我的主angular控制器代码var myApp = angular.module('myApp',['ngResource','ngRoute']); myApp.config(function ($routeProvider) […]

按$ geonear汇总

我有一个看起来像这样的集合: [ { "roadname": "foo", "data": [ { "val": 50, "loc": { "type": "Point", "coordinates": [3.197033554, 50.64611712] } } }, { "val": NULL, "loc": { "type": "Point", "coordinates": [3.197740735, 50.6460058] } } } ] }, { "roadname": "foo", "data": [ { "val": 50, "loc": { "type": "Point", "coordinates": [3.32456512, 50.2744516] } } } ] }, […]

mongodb数据库的表格和表示

我想以html的forms在node.js,express.js和angular.js中以表格forms显示mongodb数据。 我现在正在做的是这样的 route.js app.get('/superhero', function(req, res) { superhero.superhero_list(req,res); res.sendfile('./public/superhero.html'); }); superhero.js var express = require ('express') var rootRequire = require('root-require'); var bodyParser = require('body-parser'); var superheroSchema = rootRequire('Anguar/models/superhero'); module.exports = { superhero_list: function(req, res) { superheroSchema.find({}, function(err, superhero) { if (err) { return res.status(400).send({ "message": "Server error!", "err": err }); } else { return res.status(200).send({ […]

Mongoose为特定字段添加expires属性

我已经为我的Web应用程序创build了一个基于令牌的身份validation系统,并且我需要有一个令牌字段的到期date。 保持token的user模型如下: module.exports = (function() { var userSchema = new Schema({ phone: String, token: { value: { type: String, lowercase: true, trim: true } }, verificationCode: Number, createdAt: { type: Date, default: Date.now() } }); var User = mongoose.model('User', userSchema); return User; })(); 我想知道是否有任何方式有token字段的到期date属性。 其实我想在我的代码中有下面的东西来检查令牌是否过期: User.findOne({}, function( err, user ) { if (user.token.isExpired()) { // […]