node.js - Proper way to create indexes during deployment -
i creating expressjs api , using mongodb. have decent understanding of indexes , understand expensive create when there data in database.
in ms sql server create indexes when creating database tables. question handle creation of indexes in post
call in express app or achieve using scripts when deploymening application?
for example need geospatial indexing.
would index creation handled in express app this?
//express post call let col = db.collection( 'collection' ); col.createindex( // someindex ); col.insertone( //some document );
i looking best method creating 'initial' state of mongodb , creating indexes need collections before these collections contain documents.
so, may happen, have lot of data in database while deployment , not want indexing terrible. here's mongodb can help. can indexing in background not prevent read , write operations database while index builds.a simple command:
db.collection.createindex( { a: 1 }, { background: true } )
check manual details.
https://docs.mongodb.org/manual/tutorial/build-indexes-in-the-background/
Comments
Post a Comment