Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Valeri Karpov
    @vkarpov15
    @jrthib yep. You can either do schema.index({ field: 'text' }); or new Schema({ field: { type: 'String', index: 'text' } }); to create a text index. Other than that, same syntax as in node driver (see http://thecodebarbarian.com/2014/04/10/a-nodejs-perspective-on-whats-new-in-mongodb-2-6-part-i-text-search)
    Joseph Thibeault
    @jrthib
    awesome
    thanks @vkarpov15
    Richard Brookfield
    @dvideby0
    has anyone else noticed that if you use addToSet on an empty array, the first set of objects inserted are reversed? Any operation after will adhere to the order in which you specify. here is some code that we were using to test and it consistently works. Just wondering why we have to reverse the initial inserts.
    twitterFriends.findOne({screen_name: message.body.screen_name}, function(err, record){
            if(err){
              console.log(err);
              message.nack();
            }
    
            if(!record) {
              record = twitterFriends(
                {
                  screen_name: message.body.screen_name,
                  friends: []
                }
              );
              record.save(function(err) {
                if (err) {
                  console.log('error: %j', err);
                  message.nack();
                }
                console.log('create ' + record);
                data.forEach(function(friend){
                  record.friends.addToSet({screen_name: friend.screen_name, name: friend.name, id: friend.id});
                  record.save();
                });
                message.ack();
              });
            } else {
              console.log('update ' + record);
              data.forEach(function(friend){
                record.friends.addToSet({id: friend.id, name: friend.name, screen_name: friend.screen_name});
                record.save();
              });
              message.ack();
            }
          });
    Valeri Karpov
    @vkarpov15
    So $addToSet does not guarantee any particular ordering: http://docs.mongodb.org/manual/reference/operator/update/addToSet/#behavior
    on the mongodb server end that is, that's not a mongoose restriction
    although I suspect this may be a case of mongoose reversing keys. Thanks for your issue on Github, I'll look into it
    Richard Brookfield
    @dvideby0
    Does that not just refer to the order within the array? not the item in the array itself? because this behavior is 100% consistent. Its always reversed the 1st time and then as expected any time after. It never deviates from that. $addToSet only ensures that there are no duplicate items added to the set and does not affect existing duplicate elements. this seems to refer to the order in array
    otherwise how would it be able to remove duplicates?
    if items are objects
    Valeri Karpov
    @vkarpov15
    ah ok I misunderstood your question. It's the actual sub-document itself that's backwards, not the elements of the array. That's different, thanks for clarifying. I don't know off the top of my head but I'll look into it.
    Richard Brookfield
    @dvideby0
    Thank You. I reported a bug if you want to track there.. LearnBoost/mongoose#2771
    Salvador López Mendoza
    @sallomendo
    Hi !
    Valeri Karpov
    @vkarpov15
    Hi
    Bastien LE REST
    @LOLKFC
    hi everyone, there is promise "catch" in mongoose?
    Valeri Karpov
    @vkarpov15
    LearnBoost/mongoose#2308
    nope not right now.
    Much of the reason why LearnBoost/mongoose#2688 exists - ES6 is becoming the dominant promises standard and mongoose doesn't have support for it
    Bastien LE REST
    @LOLKFC
    ok thanks
    Luke A. Greenleaf
    @gishmel
    so why does required keep kicking back this error? https://gist.github.com/gishmel/0ea2a8270c3342d87a72
    so i am trying to use bodyParser in express.js and somehow the body is not populated but i am wondering the significance of the message in the properties field as well as if anyone knows why bodyParser might not be working or silently erroring out
    Nick Ferraro
    @Spidy88
    Is it normal to get duplicate 'connected' events from mongoose?
    var connection = mongoose.createConnection(mongoUrl);
    
        connection.on('connected', onConnected);
        connection.on('disconnected', onDisconnected);
        connection.on('error', onError);
    
        return connection;
    
        function onConnected() {
            logger.info('mongo connected');
        }
    
        function onDisconnected() {
            logger.info('mongo disconnected');
        }
    
        function onError(err) {
            logger.error('mongo error', {error: err});
        }
    Nick Ferraro
    @Spidy88
    nvm, issue with foreman/throng/ my code location
    Amitava Ghosh
    @aghosh47
    hi I wanted to ask about an implementation question.. In terms of SQL .. I have a Post model, User model, Tag model .. now I want to have a intermidiate model like Tagging which would be a join table of Post and Tag ... So should I make it a sub document ... or have a separate model ? https://gist.github.com/aghosh47/180481e91f2c5112941a
    Christoph Werner
    @codepunkt
    when a save errors while working with async/await, such as
    try {
      const session = new Session({ userId })
      await session.save()
    } catch (e) {
    }
    will the error be catched or do i have to do something along these lines to catch it
    const error = await session.save()
    if (error) throw new Error(error)
    ssadiks
    @ssadiks
    var code = "formatted";

    ``` (shift+enter for line break)

    var code = "formatted";

    ```

    var test = 'test';
    console.log(test);
    Dominic Böttger
    @DominicBoettger
    Hello.
    Do you know any possibilities to add options on insertMany as described in the native mongodb documentation. I want to add the option ordered: false.
    Okeke Arthur Ugochukwu
    @anextro
    Any one here
    Hajnal
    @hyhajnal
    hello. I met a problem about deep populate with mongoose
    voteSchema.statics.detail = async function(voteId){
      const vote = await this
        .findById(voteId)
        .populate('user')
        .populate({
          path: 'comments',
          populate: { 
            path: 'childs'
          }
        })
        .populate({
          path: 'comments',
          populate: { path: 'from' }
        })
        .populate({
          path: 'comments',
          populate: { path: 'to' }
        })
      return vote;
    }
    Hajnal
    @hyhajnal
    const voteSchema = new Schema({
      title: String,
      desc: String,
      create_time: Date,
      active_time: Date,
      tag: String,   
      view: Number, 
      msg: Number,
      follow: Number,
      is_voted: Number,
      user: {type: ObjectId, ref: 'User'}, 
      complex: Boolean, 
      votelist: Array,
      comments: [{type: ObjectId, ref: 'Comment'}]
    });
    const commentSchema = new Schema({
      content: String,
      time: Date,
      star: Number,
      msg: Number,
      voteId: {type: ObjectId, ref: 'Vote'},
      from: {type: ObjectId, ref: 'User'},
      to: {type: ObjectId, ref: 'User'},
      childs: [ {type: ObjectId, ref: 'Comment'} ],
    });
    I want to find a comment-reply result with childs ref filled , like recursion or deep population, any one can help?
    Hajnal
    @hyhajnal
    "comments": [
          {
            "_id": "58f777f4eaba472d05e56ab9",
            "content": "养布与音素算明文造严办步知人方。身改世而声查政每向海位速向期约。广指七基本权派证参后性共矿我不整但。",
            "star": 461,
            "msg": 92,
            "time": null,
            "from": {
              "_id": "58fc03c2b78b45f01353b058",
              "name": "武秀英",
              "psd": "etyqe5034728069932406",
              "avator": "http://dummyimage.com/6*6/f27987/79abf2&text=Mock",
              "following_count": 65,
              "follower_count": 31,
              "topic_count": 0,
              "vote_count": 61,
              "vote_join_count": 37,
              "reply_count": 19,
              "follower_count_new": 1,
              "reply_count_new": 4
            },
            "__v": 10,
            "to": {
              "_id": "58fc03c2b78b45f01353b052",
              "name": "范静",
              "psd": "qjhvo3584582169318150",
              "avator": "http://dummyimage.com/6*6/79c4f2/e7f279&text=Mock",
              "following_count": 48,
              "follower_count": 14,
              "topic_count": 7,
              "vote_count": 36,
              "vote_join_count": 42,
              "reply_count": 47,
              "follower_count_new": 9,
              "reply_count_new": 7
            },
            "voteId": "58fb8bd8116553bae1b54d95",
            "childs": [
              {
                "_id": "58f777f4eaba472d05e56ab9",
                "content": "养布与音素算明文造严办步知人方。身改世而声查政每向海位速向期约。广指七基本权派证参后性共矿我不整但。",
                "star": 461,
                "msg": 92,
                "time": null,
                "from": "58fc03c2b78b45f01353b058",
                "__v": 10,
                "to": "58fc03c2b78b45f01353b052",
                "voteId": "58fb8bd8116553bae1b54d95",
                "childs": [
                  "58f777f4eaba472d05e56ab9",
                  "58f777f4eaba472d05e56aba",
                  "58f777f4eaba472d05e56ab8",
                  "58f777f4eaba472d05e56ab9",
                  "58f777f4eaba472d05e56abc",
                  null,
                  "58f777f4eaba472d05e56abd",
                  "58f777f4eaba472d05e56abd",
                  "58f777f4eaba472d05e56aba",
                  "58f777f4eaba472d05e56abc"
                ]
              }]
    Thomas Sieverding
    @Bajix
    Is there a way of extending the Query prototype for a schema? Or even like monkey patching
    My use-case is to add helpers for applying selection behavior
    Berian
    @chaiwa-berian
    How do I handle error when MongoDB is down? Tested this endpoint, but it doesn't get hit at all if the request is sent when the database server is down. I am using mongoose
    //GET api/silcgroups
    exports.getAllSILCGroups = function(req, res){
        SILCGroup.find(req.query, function(err, silcgroups){
            if(err) {
                console.log(err);
                return res.json(err);
            }
            else  return res.json(silcgroups);
        });
    };
    Cromie Enterprises
    @cromieent
    Hey folks - where do I go to get a good overview of the types available and the syntax to use when building a schema? I'm a newbie coming straight from a class and need more detail.
    Roman Ovidiu Robert
    @RORVI
    Hi everyone! I'm having a weird issue regarding some fields for a few mongoose objects. In Robo3T, they have placed $ signs before them, which i know is a big no-no when working with mongodb. Also, the _bsontype is "Double". But the returned objects are empty. Also, i cannot edit those fields manually in Robo3T, to fix the issue. The data insertion was done with mongoose-double. Has anyone encountered such a thing ? When i try and look at the field value in my Express app, i can only see [object : Object].
    but please take care with the project structure as well. here is a more complex example, which i've been getting inspiration from: https://github.com/Trustroots/trustroots
    good luck!