Seeking guidance as a newcomer to MongoDB. I am attempting to create a collection in my database with a single document that contains a key `cities`, which is an array comprising of 124247 objects. Below is the code snippet for reference:
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require("mongoose");
const cities = require('cities.json');
const Schema = mongoose.Schema;
const db = mongoose.connection;
const app = express();
mongoose.connect("mongodb://localhost:27017/cities");
db.once("open", function() {
console.log("Connection established successfully.");
})
const cityScheme = new Schema({
cities: Array
});
const WorldCities = mongoose.model("WorldCities", cityScheme);
const myCities = new WorldCities({
cities: cities
}).save().then(data => console.log({}.toString.call(data.cities), 'dataaa'));
WorldCities.find({
name: "Yerevan"
}, function(err, data) {
console.log(data, 'Armenia');
});
cityScheme.statics.getSearchedcity = function(res) {
this.find({}, (err, citysList) => res.json({
citysList
}));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.get('/api/city', (req, res) => {
})
app.listen(3000);
You can access the cities.json file link here: Cities.json.
I am currently looking to retrieve the city named Yerevan but unsure of the approach to take. Any insights would be appreciated.