Mongoose with ElasticSearch in node.js - node.js

I am using mongoDB in node.js with mongoose now I want to use ElasticSearch. Now can anyone please tell me would it be better to use mongoosastic, an npm module for both mongoose and ElasticSearch, or should I install ElasticSearch separately?

Since you are already using mongoose, you should use mongoosastic.
Mongoosastic already depends on the ElasticSearch Module to perform ElasticSearch operations

Related

Handling Mongoose connection failure in NestJS

I am new to NestJS.
I am trying to connect to mongo instance, like this MongooseModule.forRoot('mongodb://localhost:27017/demo')
How can I handle no connection here.
Probably you wrote wrong database URL.
You have to follow official documentation:
Mongo

Is there any packages support database ORMs in nodejs like model in Laravel (PHP)?

I'm new to Nodejs and express, now I'm write pure query to
interact with database so I'm looking for packages support DB query. Thank in advance !
I recommend https://www.npmjs.com/package/typeorm
more details visit their github ; https://github.com/typeorm/typeorm
I am using it with my NodeJS server and PostgreSQL DB

How to create a ttl index in mongodb atlas Using mongoose?

I'm building a node app and using mongoose
This is my first time creating a TTL index on mongodb atlas, idk because for some reason it does not seem to work.
node version v14.16.0
mongoose version 5.12.5

How to use mongoose in two packages?

I'm using Lerna to handle multiple packages in my repo.
Basically, I have a package #pkg/server where my Node/Express App is and an other package #pkg/model where my mongoose Schemas reside.
My REST API is using some of the models, with an import ModelA from '#pkg/model'.
The problem is that both of these packages have mongoose as a dependency (the #pkg/server uses mongoose to establish a connection to the mongoDB server, and #pkg/model uses mongoose to define schemas and models).
In my server, whenever I try to call ModelA.find(...), it just hangs forever. From the mongoose docs, it looks like I have to register a model to a mongoose connection and not to the mongoose object itself.
My first guess is to pass the connection object created by the server to the #pkg/model and then register the models to this connection object.
My question is, is this the right way to do it? Or is there a way to do something like (in the #pkg/server) mongoose.loadSchemas(#pkg/model) ?
What I have ended up doing, is that I'm passing the connection to the package requiring mongoose thus sharing the connection between packages.
Some package can register models, an other one can make queries, etc...

how to get all collection names from a specific db in mongo using nodejs

Recently I want to get all collection names from a db in mongo. And my develop environment is nodejs + express + mongoose. I tried mongooser.conncetion.db.getCollectionNames(or listCollections or collections), but any does not work. I guess the it is the version problem, maybe the latest mongoose api does not contain those functions.
Consequently, how to obtain all collection names from a db using mongoose?
Thank you so much for any help!

Resources