1

So I have a collection in which I dump logs.Each log have EndUserId field. The mongoose schema is as follows:

var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var ChatbotLogsSchema = new Schema({

    EndUserId: {
        type: String
    },
    MessageType: {
        type: String
    },
    Message:{
        type: String
    },
    CreatedDateTime: {
        type: Date, default: Date.now
    },
    UpdatedDateTime: {
        type: Date, default: Date.now
    },
    SentimentScore: {
        type: Number
    },
    EngageWeight: {
        type: Number
    }
}, { timestamps: { createdAt: 'CreatedDateTime',updatedAt:"UpdatedDateTime" } },{ collection: "ChatbotLogs" });

I want to get list of distinct EndUserId which are logged in last 5 minutes and were not present in collection previously.

What will be the efficient way to achieve this?

Edit :This question is different than Query to get last X minutes data with Mongodb As I want to get only new users which were not present previously in collection.

dd619
  • 5,910
  • 8
  • 35
  • 60
  • Possible duplicate of [Query to get last X minutes data with Mongodb](https://stackoverflow.com/questions/18233945/query-to-get-last-x-minutes-data-with-mongodb) – David R Jun 20 '19 at 12:09
  • "were not present in the collection previously." Do you mean that user logged in for the first time? – Thamaraiselvam Jun 20 '19 at 12:21
  • @Thamaraiselvam Yes. That's exactly I mean. – dd619 Jun 20 '19 at 12:23
  • `Mongoose.distinct` with conditions did not work? – Thamaraiselvam Jun 20 '19 at 12:23
  • @Thamaraiselvam it works but it doesn't tell me if its a new user. Combination of more than one query may get me a solution but i just want to know if there any efficient way to do this – dd619 Jun 20 '19 at 13:00

0 Answers0