V
V
Vlad Timofeev2015-03-03 02:10:36
JavaScript
Vlad Timofeev, 2015-03-03 02:10:36

Why is mongo not adding entries to the collection correctly?

Good day.
There is a comment schema:

var commentSchema = mongoose.Schema({
    text: String,
    postNum: Number,
    num: Number,
    rating: [],
    addtime: String,
    to: Number
});

So, saving all the new comments with the save method, I noticed: after the 12th entry, it starts to cram new entries in front of all existing ones.
c00cc3ef97c64e7e8364ee1633112814.png
(green - good))) red - something has already gone wrong)
--------------------------------- ---------------------
I don't know if it helps, but I usually save it like this:
Comment.count({}, function (err, count) {
  var newComment = new Comment;
  newComment.text = comment;
  newComment.authorId = authorId;
  newComment.num = count + 1;
  newComment.postNum = postNum;
        newComment.save(function (err) {
           if(err) throw err;
.....
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2015-03-03
@PyTiMa

Did not create indexes on fields? when creating, you can specify storage sorting, I don’t know for sure whether this affects the selection without using this field. And so I advise you not to focus on the order of insertion, but to use the usual "sort" tool to specify exactly in which order to show.
You can also try directly, through the console, to make a request, if it returns correctly, then the interface is stupid.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question