mongodb

MongoDB - Autocomplete - Get all words starting with X

为君一笑 提交于 2021-01-29 17:56:23
问题 I have a collection (users) with the following structure: { propA: { words: ["i", "have", "an","important", "question"] } } I want to get autocomplete options from the db for some input in my website. So first, i think that i need to create an index for propA.words. Maybe something like this(?): db.users.createIndex({ "propA.words" : 1 }) Second, how can i query this index to get all the words starting with X? For example, for the string "i", the query will retrieve ["i", "important"]. Thanks

Spring Boot handle multiple MongoTemplates for Multi Cluster MongoDB

心已入冬 提交于 2021-01-29 17:44:11
问题 I have to implement multi-tenancy using spring-boot, mongodb. Previously I was using same cluster so things were simple enough. Now each tenant would have its own database in its own cluster. So I was thinking of having multiple mongoTemplates managed in a single application. My requirements: I wanted all Spring configuration in Java code/annotations. (I hate XML!) I wanted Spring to manage both the Mongo and MongoTemplate objects. I wanted to use MongoRepository Interface beans and have the

Nested Relations MongoDb

别说谁变了你拦得住时间么 提交于 2021-01-29 17:33:59
问题 I need some help. I have 2 MongoDB collections that I want to relate. One is for categories and the other for multimedia content. A category can contain one multimedia content and Many Childs Categories. After execute aggregation by passing the pipeline I get the Returned Format (See image 1): Media elements inside Category.Media and Child categories inside Category.Childs. My problem is that I don't know how I can insert again Media inside Child Categories (See image 2) I also leave below

MongoDB get all values of 1 field

ε祈祈猫儿з 提交于 2021-01-29 17:18:48
问题 So I know that in mongodb, I can get all values and then iterate through them but I was wondering if in mongodb there is an option to get only a certain field. So for example suppose my collection is structured as follows: {_id: { field1,field2,field3} } {description: { field1,field2,field3, data:{ field1,field2,field3 } } } {otherdata: {field1,field2,field3} } Now, I need the value of description.data.field1 so any suggestions on how to do that? So far I have tried using following commands:

mongodb can't do transaction in Go and always got Cannot create namespace in multi-document transaction

三世轮回 提交于 2021-01-29 17:11:42
问题 I am trying to create a function that InsertOne data by wrap transaction, and I already to replica set in mongodb also, I tried in local and and MongoDB atlas the error were same, here is the code: const MONGODB_URI = "mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs" ctx := context.Background() client, err := mongo.Connect(ctx, options.Client().ApplyURI(MONGODB_URI)) if err != nil { panic(err) } db := client.Database("production") defer db.Client().Disconnect(ctx) col

Optimizing Airflow Task that transfers data from BigQuery into MongoDB

风流意气都作罢 提交于 2021-01-29 16:32:28
问题 I need to improve the performance of an Airflow task that transfers data from BigQuery to MongoDB. The relevant task in my DAG uses a PythonOperator , and simply calls the following python function to transfer a single table/collection: def transfer_full_table(table_name): start_time = time.time() # (1) Connect to BigQuery + Mongo DB bq = bigquery.Client() cluster = MongoClient(MONGO_URI) db = cluster["dbname"] print(f'(1) Connected to BQ + Mongo: {round(time.time() - start_time, 5)}') # (2)-

Cannot use Mongo's Filter with DateTime and BsonString?

孤者浪人 提交于 2021-01-29 15:23:50
问题 I'm using C3 with mongo and I'm trying to query documents by dateCreated property. For example , if I extract the first record by : var models = await c.FindAsync(a=>true); var list = await models.ToListAsync(); list.First().Dump(); Then I see the result : Please notice that the value is BsonString , and that I have no entity behind it. The problem is that now , I want to query the collection based on datetime : So I did this : var filter = Builders<BsonDocument> .Filter .And ( Builders

mongodb mongoengine filter document on nexted EmbeddedDocumentLIst fields

本秂侑毒 提交于 2021-01-29 15:23:10
问题 I have a document with a EmbeddedDocumentList inside an other EmbeddedDocumentlist, I need to filter the collections retrieving only the documents that have a specified value for a field inside the inner EmbeddedDocumentList the reduced version of my models is: class RecipeIngredient(EmbeddedDocument): ingredient = ReferenceField(Ingredient, required=True) quantity = IntField(required=True) class RecipeLocalData(EmbeddedDocument): price = FloatField(required=True) enabled = BooleanField

NodeJs api with mongoose any request go to another collection efficient

主宰稳场 提交于 2021-01-29 15:15:20
问题 I'm write nodeJs api for app with users and I want for each user to use another mongo collection. I recognize each user with the URL address in the params fields. everything is work fine. But when I go to collection dynamically it's very slow. any one idea how to do this faster? thanks in advance ;) app.js this code do req in 2.5 seconds POST /login 200 2487.531 ms - 206 app.use("/:businessUrl", (req, res, next) => { console.log(req.params.businessUrl); mongoose .connect(process.env.MONGO_URI

How to run mongo shell commands in Node.js Mongoose?

╄→гoц情女王★ 提交于 2021-01-29 15:06:32
问题 I would like to run the isMaster() command within my node.js project. The problem is that I'm unsure how to run any sort of mongo shell command via js code. I know in Python you can use client.admin.command('ismaster') . If this isn't achievable within mongoose, I am open to using the mongodb package, but I'd like to keep it solely mongoose. I am just trying to test if a connection is within a primary node. Thanks! 回答1: You can use either Db.executeDbAdminCommand or Db.admin().command. This