Relative Content

Tag Archive for node.jsmongodb

time out mongo db err how can i resolve this please any one

Error connecting to MongoDB: MongooseServerSelectionError: Server selection timed out after 30000 ms
at _handleConnectionErrors (D:developmentdevopProductnode_modulesmongooselibconnection.js:909:11)
at NativeConnection.openUri (D:developmentdevopProductnode_modulesmongooselibconnection.js:860:11)
at runNextTicks (node:internal/process/task_queues:65:5)
at listOnTimeout (node:internal/timers:555:9)
at process.processTimers (node:internal/timers:529:7)
at async connectDB (D:developmentdevopProductconfigdb.js:15:9) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
servers: Map(0) {},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: ‘atlas-xxxxx-shard-0’,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}

Resume mongodb stream from the point where it stopped

I am streaming huge amount of data from mongodb to other service.
For this i am using mongodb stream. But due to some reason if stream stops i want to rerun the job from where it stopped rather than starting it from start.
My question is if i store the last document id where it failed and rerun the stream from that document will this work ? Does streaming mongodb collection preserve same order every time or do i need to add sortBy for this ?

Mongoose model not enforcing unique in two places

I’m working on a personal project and I’m working on user signup, one of the major things is having users with unique usernames and unique emails. So far I have it enforcing it on email, but for some reason it just will not do it for usernames either. It seems that when I put it in both areas it just overrides each other and allows for duplicates. Here is my model code: