[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: MongoDB timeout error and tags: ['aggregation', 'queries', 'java', 'mongodb-shell']

[User]
Text:I am facing timeout error when i am fetching same collection simultaneously. Could you help me fix this issue ? i have mentioned the error belowTimed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@b586e86. Client view of cluster state is {type=REPLICA_SET, servers={, type=UNKNOWN, state=CONNECTING}, {address=, type=UNKNOWN, state=CONNECTING}, {address=](), type=UNKNOWN, state=CONNECTING}]
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: "_id" field mapped to null || PojoCodecRegistry and tags: ['java']

[User]
Text:Hi,I am using PojoCodecRegistry (BSON library) and need to map the the "_id " field of the Mongo DB document to user defined POJO field.However, the “_id” field is getting mapped to null. I have a property named as :I am using mongo java 4.0 driver and JAVA 8
Code:

[Assistant]
Text:Hello Aditya,Can you provide details about how you are mapping the _id field - please include your Pojo class with the _id field mapping.However, the “_id” field is getting mapped to null. I have a property named as :Also, please include code you had tried to build the Pojo object and insert into the collection.
Code:_id_id

[User]
Text:Thanks So very much for acknowledging the concern.
The POJO class is something like below ::package org.mongo;//imports@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Student {
public Student() {
}}Basically this error is occurring when the BSON is deserialized to Java Object.  _id field is mapped to null. Rest all other fields are mapped properly.Please let me know how to solve this problem.
Code:@BsonProperty("_id")
@JsonProperty("_id")
private ObjectId _id;

private String name;
private int age;
private int courseCount;
private String email;
private boolean isVerified;
private ArrayList<String> hobbies;
private ContactDetails contactDetails;
private ArrayList<Marks> marks;

// Getters and Setters

// toString() method

[Assistant]
Text:Basically this error is occurring when the BSON is deserialized to Java Object. _id field is mapped to null.The Pojo class is good.You can create Pojo objects and insert into a MongoDB collection as documents and retrieve them - without problem. All this using the default driver created ObjectId.You can post the code related with creating the object (new Student(), setting the properties, etc.,), how you are inserting and retrieving.Also, see code examples at: MongoDB Java Driver - POJOs.
Code:ObjectIdnew Student()

[Assistant]
Text:Is there any solution for the above issue I have the same problem too. Thanks
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: How to sum up one record per day for one month? and tags: ['aggregation']

[User]
Text:Hi
I’m trying to do to aggregate, sum up values in a month, but i only want to sum 1 entry per day, i tried to use $limit before the group but only get 1 entry return.Thanks.
Code:[
    {
        $match:
        {
            "fPort": 60,
            "rxInfo.time":
                {
                    "$gte": "2020-12-01T00:00:00.000000Z",
                    "$lte": "2020-12-31T59:59:59.935Z"
                }
        }
    },
    { $limit: '1' }, ///// This only returns 1 record and not 1 per day.
    {
        $group:
            {
                _id: "9cd9cb00000124c1",
                "Total":
                    {
                        "$sum": "$object.TotalDaily"
                    }
            }
    }
]

[Assistant]
Text:Hello @Q_Lion, Welcome to MongoDB Developer Community,As i can understand your question, you need to get count of documents yearly or monthly or daily,You can use $year, $month, $dayOfMinth Date Expression Operators.Example for Daily document count,Example for Monthly document count,You can replace yourDateFieldName to your collection field, and put your $match stage before this $group stage.
Code:[{
    $group: {
        _id: {
            year: { $year: "$yourDateFieldName" },
            month: { $month: "$yourDateFieldName" },
            day: { $dayOfMonth: "$yourDateFieldName" }
        },
        Total: { $sum: 1 }
    }
}]
[{
    $group: {
        _id: {
            year: { $year: "$yourDateFieldName" },
            month: { $month: "$yourDateFieldName" }
        },
        Total: { $sum: 1 }
    }
}]
yourDateFieldName$match$group

[User]
Text:I think i have found the query.i managed to get 1 record per day and sun the values for 1 month, Thanks
Code:[
    {
        $match:
                {
                    "fPort": 60,
                    "rxInfo.time":
                                    {
                                        "$gte": "2020-12-01T00:00:00.000000Z",
                                        "$lte": "2020-12-31T59:59:59.99"
                                    }
                }
    },
    {
        $project:
                {
                    _id:1,
                    year:
                            {
                                $year:
                                        {
                                            $dateFromString:
                                                            {
                                                                dateString:
                                                                            {"$arrayElemAt": [ "$rxInfo.time", 0 ] }
                                                            }
                                        }
                            },
                    month:
                            {
                                $month:
                                        {
                                            $dateFromString:
                                                            {
                                                                dateString:
                                                                            {"$arrayElemAt": [ "$rxInfo.time", 0 ] }
                                                            }
                                        }
                            },
                    day:
                            {
                                $dayOfMonth:
                                        {
                                            $dateFromString:
                                                            {
                                                                dateString:
                                                                            {"$arrayElemAt": [ "$rxInfo.time", 0 ] }
                                                            }
                                        }
                            },
                    sum : "$object.TotalDaily"
                }
    },
    {
        $group:
                {
                    _id:
                        {
                            year:"$year",
                            month:"$month",
                            day:"$day"
                        },
                    TotalPerDay:
                        {
                            $sum:"$sum"
                        }
                }
    },
    {
        $group:
                {
                    _id: "9cd9cb00000124c1",
                    "MonthlyTotal":
                        {
                            "$sum": "$TotalPerDay"
                        },
                }
    }
]

[User]
Text:$object.TotalDailyHi @turivishal Thanks for the response,no i don’t want count it, i want to add value of  $object.TotalDaily together, but u only want to add 1 value per day, per month.I tried to use $group this way but i get a error.but keeps telling me “can’t convert from BSON type array to Date”.Thanks
Code:$object.TotalDaily{
  _id: {
            year:{$year:"$rxInfo.time"},
            month:{$month:"$rxInfo.time"},
            day:{$dayOfMonth:"$rxInfo.time"}
        },
        "Total":
        {
          "$sum": "$object.TotalDaily"
        }
}

[Assistant]
Text:The field "$rxInfo.time" having string type date and also inside an array, it should be date type and outside the array, you need to deconstruct the rxInfo array using $unwind, and than use $group stage.You have already did in your second reply, you can convert it using $dateFromString or $toDate Date Expression Operators, Before the $group stage inside $addFields, or inside the $group stage that you have already did.
Code:"$rxInfo.time"rxInfo$group$group$addFields$group

[Assistant]
Text:Hi, I need to order all the data by months from an aggregate in a list recordsomething like thisJanuary01-01-2020filed1,field2,field302-01-2020fieild1,field2,field3February01-02-2020field1,field2,field302-02-2020field1,field2,field3April01-04-2020field1,field2,field302-04-2020field1,field2,field3And I have no clue how to do it.
Code:

[Assistant]
Text:Hello @jack_austin, Welcome to the MongoDB community forum,This topic is not related to the current topic, Can you please ask your question in a new post?
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Help with Mongo Realm and NextJS with User Authentication? and tags: ['node-js', 'app-services-user-auth', 'next-js', 'developer-hub']

[User]
Text:Hello. I’m new to Mongo, and Next JS.
I read the article on How to Integrate MongoDB Into Your Next.js App today and now I’m looking for more!I’d like to build a NextJS app that uses Realm for user authentication with protected API routes for user data. Does anyone have a link to an tutorial article, or Github Repo or any other resources to do this?Looking forward to your responses.
Code:

[Assistant]
Text:Hey Brian - While I don’t think we have one, it seems like Vercel has an example of using Realm with Next.JS. Would this help? - Example with Monogdb ReamlWeb (#14555) · vercel/next.js@1b5ca78 · GitHub
Code:

[User]
Text:I will take a look when I can.
Code:

[Assistant]
Text:Hey Brian,Depending on your approach to authentication, you’d either use the Realm Web SDK or the Node.js SDK. But when it comes to Auth, are you trying to use Realm solely for auth or do you need other realm features in your app. The only reason I ask is that if you just need user authentication, a specific library like Next-Auth could be a better choice.
Code:

[User]
Text:I’m planning to build a Admin/Dashboard app for authenticated users only. Non-authenticated users will only see a logon screen.I would love to use NextAuth if it supports Realm features. Other developers in my company are working with Realm for other, non-Next JS apps, so I think I need to find a way to tie into Realm for authentication.Does NextAuth work with Realm?
Code:

[Assistant]
Text:Hey Brian - not sure what your implementation details are for auth in the other apps, but it seems like NextAuth would work with Realm if you use JWT Authentication. After using NextAuth to sign in, you can pass in the JWT that you get from the callback to Realm’s JWT Auth provider
Code:

[Assistant]
Text:How can assure I can call app.currentUser
in the getServerSideProps ? It seems undefined if I call It on getServerSideProps
Code:

[Assistant]
Text:Is there a concrete example for this? In the docs https://www.mongodb.com/docs/realm/web/nextjs/#log-the-user-in it saysIn a real application, you would want to have a more complex authentication flow. For more information, refer to the Next.js authentication documentation.Could anyone share of an example using Next Auth and Realm Web?
Code:

[Assistant]
Text:I’d also like to see a concrete example of a production-ready authentication flow.@Alexandar_Dimcevski did you manage to find a good example of figure out a good approach?
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Getting Error while connecting to MongoDB using Node.js and tags: ['node-js', 'mongoose-odm']

[User]
Text:I am getting this error, please help:
Code:<C:\AI\ai-real-estate-friend\node_modules\mongoose\lib\connection.js:755
    err = new ServerSelectionError();
          ^

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
    at _handleConnectionErrors (C:\AI\ai-real-estate-friend\node_modules\mongoose\lib\connection.js:755:11)
    at NativeConnection.openUri (C:\AI\ai-real-estate-friend\node_modules\mongoose\lib\connection.js:730:11)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:538:9)
    at process.processTimers (node:internal/timers:512:7) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      'localhost:27017' => ServerDescription {
        address: 'localhost:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 27239058,
        lastWriteDate: 0,
        error: MongoNetworkError: connect ECONNREFUSED ::1:27017
            at connectionFailureError (C:\AI\ai-real-estate-friend\node_modules\mongodb\lib\cmap\connect.js:383:20)
            at Socket.<anonymous> (C:\AI\ai-real-estate-friend\node_modules\mongodb\lib\cmap\connect.js:307:22)
            at Object.onceWrapper (node:events:628:26)
            at Socket.emit (node:events:513:28)
            at emitErrorNT (node:internal/streams/destroy:151:8)
            at emitErrorCloseNT (node:internal/streams/destroy:116:3)
            at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
          cause: Error: connect ECONNREFUSED ::1:27017
              at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
            errno: -4078,
            code: 'ECONNREFUSED',
            syscall: 'connect',
            address: '::1',
            port: 27017
          },
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
        },
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
      }
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
}

[Assistant]
Text:Hi  @Musa_Mazhar,Welcome to the MongoDB Community forums It seems like MongoDB is not running or is not listening on port 27017.To troubleshoot this error, you can try:Let us know if you need any further help!Best,
Kushagra
Code:

[User]
Text:Hi Kushagra,Good day to you.Here’s the snapshot from cmd window where it shows that MongoDB is running on port 27017. But somehow when I use the same cmd for Node.js, MongoDB gives above error.

MongoDB1526×787 40.6 KB

Code:

[Assistant]
Text:The::1:27017part in the error messageECONNREFUSED ::1:27017indicates that your localhost resolve to the IPv6 address rather than the IPv4 127.0.0.1.  Try replacing localhost in your connection string with 127.0.0.1.
Code:::1:27017ECONNREFUSED ::1:27017

[User]
Text:Hi Steevej, so i replaced the localhost in connection string with 127.0.0.1. Here’s the code for server.js file which I am trying to run in cmd using ‘npm start’
Code:const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');

const app = express();
const PORT = process.env.PORT || 5000;

app.use(cors());
app.use(express.json());

mongoose.connect('mongodb://localhost:127.0.0.1/ai-real-estate-friend');

const connection = mongoose.connection;
connection.once('open', () => {
  console.log('MongoDB database connection established successfully');
});

app.listen(PORT, () => {
  console.log(`Server is running on port: ${PORT}`);
});

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});

const listingSchema = new mongoose.Schema({
  title: String,
  description: String,
  address: String,
  city: String,
  state: String,
  zip: String,
  price: Number,
  image: String
});

const Listing = mongoose.model('Listing', listingSchema);

app.get('/api', async (req, res) => {
  try {
    const listings = await Listing.find();
    res.json(listings);
  } catch (error) {
    console.error(error);
    res.status(500).send('Server error');
  }
});

[Assistant]
Text:i replaced the localhost in connection string with 127.0.0.1You did not.You replaced the port 27017 with 127.0.0.1.mongoose.connect('mongodb://localhost:127.0.0.1/ai-real-estate-friend');
Code:mongoose.connect('mongodb://localhost:127.0.0.1/ai-real-estate-friend');

[User]
Text:Okay, maybe I am doing it wrong. Can you please guide me how to to replace the port?
Code:

[User]
Text:Thank you so much. I didn’t correct it first, then I replaced it with. It worked. Thank you.
Code:mongoose.connect('mongodb://127.0.0.1:27017/ai-realestate-friend');


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Connection to mongodb://127.0.0.1:27017 refused and tags: ['compass', 'mongodb-shell', 'server']

[User]
Text:Hi,I believe that this question has been tackled here Connect ECONNREFUSED 127.0.0.1:27017 in Mongodb Compass but I am not entirely happy with it.I really closely follow the documentation https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/#installing-mongodb-6.0-edition-edition and https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/#run-mongodb-community-edition but in spite of that when I tryI obtain the deceptively optimistic messagewhile in fact running mongosh givesAlthough I do believe the solution exists, it is quite intimidating that it is not reflected in the docs. Currently, I am only able to run mongodb locally as a superuser…
Code:brew services start mongodb-community@6.0
==> Successfully started `mongodb-community`
mongoshmongosh
Current Mongosh Log ID:	63f0f50dc46c87b2ca8c78fc
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.7.1
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
mongodbsuperuser

[Assistant]
Text:I have the same problem
Code:❯ brew services start mongodb-community@6.0

==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
❯ mongosh
Current Mongosh Log ID:	63f2912b4d7d8dffb21c4f96
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.7.1
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017```

[Assistant]
Text:The error ECONNREFUSED means mongodb is not listening at the given address and port. The fact that mongodb has been started correctly does not mean that it listens to the given address and port.It is also possible that your firewall settings are preventing mongosh/Compass to connect.The configuration file will tell you which address and port are used by mongod.The commands ss or netstat can also be used to determine on which address/port mongod is listening.
Code:

[User]
Text:Thank you for your reply. So let’s try to figure out what’s going on here:Do I get it right that the problem could be in the fact that the port 27017 is not explicitly specified at the bindIp key?For the sake of completeness, I had a glimpse at the mongo.log file mentioned in the config, and this what happens when I try to run the mongosh command after starting the mongodb as a service:Is it helpful somehow? Thank you
Code:/opt/homebrew/etc/mongod.confsystemLog:
  destination: file
  path: /opt/homebrew/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /opt/homebrew/var/mongodb
net:
  bindIp: 127.0.0.1, ::1
  ipv6: true
27017bindIpmongo.logmongoshmongodb{"t":{"$date":"2023-03-02T12:15:44.509+01:00"},"s":"I",  "c":"CONTROL",  "id":20698,   "ctx":"-","msg":"***** SERVER RESTARTED *****"}
{"t":{"$date":"2023-03-02T12:15:44.514+01:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2023-03-02T12:15:44.518+01:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"thread1","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-03-02T12:15:44.544+01:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"thread1","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2023-03-02T12:15:44.549+01:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-03-02T12:15:44.549+01:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-03-02T12:15:44.549+01:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}}
{"t":{"$date":"2023-03-02T12:15:44.549+01:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"thread1","msg":"Multi threading initialized"}
{"t":{"$date":"2023-03-02T12:15:44.550+01:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":69920,"port":27017,"dbPath":"/opt/homebrew/var/mongodb","architecture":"64-bit","host":"Jiri-MacBook-Air-2.local"}}
{"t":{"$date":"2023-03-02T12:15:44.550+01:00"},"s":"I",  "c":"CONTROL",  "id":23352,   "ctx":"initandlisten","msg":"Unable to resolve sysctl {sysctlName} (number) ","attr":{"sysctlName":"hw.cpufrequency"}}
{"t":{"$date":"2023-03-02T12:15:44.550+01:00"},"s":"I",  "c":"CONTROL",  "id":23351,   "ctx":"initandlisten","msg":"{sysctlName} unavailable","attr":{"sysctlName":"machdep.cpu.features"}}
{"t":{"$date":"2023-03-02T12:15:44.550+01:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.4","gitVersion":"44ff59461c1353638a71e710f385a566bcd2f547","modules":[],"allocator":"system","environment":{"distarch":"aarch64","target_arch":"aarch64"}}}}
{"t":{"$date":"2023-03-02T12:15:44.550+01:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"22.3.0"}}}
{"t":{"$date":"2023-03-02T12:15:44.550+01:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/opt/homebrew/etc/mongod.conf","net":{"bindIp":"127.0.0.1, ::1","ipv6":true},"storage":{"dbPath":"/opt/homebrew/var/mongodb"},"systemLog":{"destination":"file","logAppend":true,"path":"/opt/homebrew/var/log/mongodb/mongo.log"}}}}
{"t":{"$date":"2023-03-02T12:15:44.552+01:00"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"initandlisten","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"acceptor TCP fast open","option":{"level":6,"name":261,"data":"00 04 00 00"},"error":{"what":"set_option: Invalid argument","message":"Invalid argument","category":"asio.system","value":22}}}
{"t":{"$date":"2023-03-02T12:15:44.552+01:00"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"initandlisten","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"acceptor TCP fast open","option":{"level":6,"name":261,"data":"00 04 00 00"},"error":{"what":"set_option: Invalid argument","message":"Invalid argument","category":"asio.system","value":22}}}
{"t":{"$date":"2023-03-02T12:15:44.553+01:00"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/opt/homebrew/var/mongodb","storageEngine":"wiredTiger"}}
{"t":{"$date":"2023-03-02T12:15:44.553+01:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=7680M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,remove=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=2000),statistics_log=(wait=0),json_output=(error,message),verbose=[recovery_progress:1,checkpoint_progress:1,compact_progress:1,backup:0,checkpoint:0,compact:0,evict:0,history_store:0,recovery:0,rts:0,salvage:0,tiered:0,timestamp:0,transaction:0,verify:0,log:0],"}}
{"t":{"$date":"2023-03-02T12:15:45.203+01:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":13,"message":"[1677755745:202842][69920:0x1f00cc140], wiredtiger_open: [WT_VERB_DEFAULT][ERROR]: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 805: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{"t":{"$date":"2023-03-02T12:15:45.204+01:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":13,"message":"[1677755745:204727][69920:0x1f00cc140], wiredtiger_open: [WT_VERB_DEFAULT][ERROR]: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 805: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{"t":{"$date":"2023-03-02T12:15:45.204+01:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":13,"message":"[1677755745:204945][69920:0x1f00cc140], wiredtiger_open: [WT_VERB_DEFAULT][ERROR]: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 805: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{"t":{"$date":"2023-03-02T12:15:45.204+01:00"},"s":"W",  "c":"STORAGE",  "id":22347,   "ctx":"initandlisten","msg":"Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade."}
{"t":{"$date":"2023-03-02T12:15:45.204+01:00"},"s":"F",  "c":"STORAGE",  "id":28595,   "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"13: Permission denied"}}
{"t":{"$date":"2023-03-02T12:15:45.205+01:00"},"s":"F",  "c":"ASSERT",   "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28595,"file":"src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp","line":708}}
{"t":{"$date":"2023-03-02T12:15:45.205+01:00"},"s":"F",  "c":"ASSERT",   "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

[Assistant]
Text:Is it helpful somehow?Very useful indeed.You have to fix the following file permission errors.  I do not know how to do that on iOS.
Code:{"t":{"$date":"2023-03-02T12:15:45.203+01:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":13,"message":"[1677755745:202842][69920:0x1f00cc140], wiredtiger_open: [WT_VERB_DEFAULT][ERROR]: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 805: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{"t":{"$date":"2023-03-02T12:15:45.204+01:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":13,"message":"[1677755745:204727][69920:0x1f00cc140], wiredtiger_open: [WT_VERB_DEFAULT][ERROR]: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 805: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{"t":{"$date":"2023-03-02T12:15:45.204+01:00"},"s":"E",  "c":"WT",       "id":22435,   "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":13,"message":"[1677755745:204945][69920:0x1f00cc140], wiredtiger_open: [WT_VERB_DEFAULT][ERROR]: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 805: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}

[User]
Text:@steevej You were right, I had to change the permission for WiredTiger.turtle and several other files. This state was probably a relict of the time when I started the process as superuser.Now I am a better mongodb user, thank you
Code:WiredTiger.turtlesuperusermongodb


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Storing Images for E-Commerce Application and tags: ['data-modeling']

[User]
Text:Ok… I’m a newbe when it comes to MongoDB but I have a question that  need a little more info on than just typing in a Google Search…I am building a version of an E-Commerce platform… I need to allow store owners to upload images (max of 5) for a product image gallery…My question is what is the best way to store them… My initial thought is to store them in their own database external to MongoDB and just link to the image through Embedded docs in the Product collection.Is this the best way… Or is there other options for me to look at?
Code:

[Assistant]
Text:Hello @David_Thompson, take a look at this post with discussion and information about storing images in MongoDB database:
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Lookup & populate objects in array and tags: ['aggregation']

[User]
Text:I have 2 collections (users and tenants). Simplified, the user looks like this:Simplified tenant model looks like this:And I’d need to query a user with aggregated tenants, so ideally add a new field tenant next to the tenantId with the actual tenant document, like this:I know it can be done - it seems so simple, but I’ve been banging my head agains the wall because of it So far I’ve tried various combinations of $lookup, $project with $map, $mergeObject with $arrayElemAt, but nothing seems to cut it… The closest answer I cloud find was this: https://stackoverflow.com/questions/60342985, but I just don’t seem to be able to adapt it. Can anyone see a way, please? Btw. (a bit unrelated) - if I $lookup the tenants and save them into a new field:The order of aggregatedAssociatedTenants is different than the order of associatedTenants. Doesn’t $lookup preserve the order of the original array?
Code:{
  "_id": ObjectId("..."),
  "associatedTenants": [{
    "tenantId": ObjectId("A"),
    "role": "foo"
  }, {
    "tenantId": ObjectId("B"),
    "role": "bar"
  }]
}
{
  "_id": ObjectId("A"),
  "name": "Lorem"
}
tenanttenantId{
  "_id": ObjectId("..."),
  "associatedTenants": [{
    "tenantId": ObjectId("A"),
    "role": "foo",
    "tenant": {
      "name": "Lorem"
    }
  }, {
    "tenantId": ObjectId("B"),
    "role": "bar",
    "tenant": {
      "name": "Ipsum"
    }
  }]
}
$lookup$project$map$mergeObject$arrayElemAt$lookup$lookup: {
  from: "tenants",
  localField: "associatedTenants.tenantId",
  foreignField: "_id",
  as: "aggregatedAssociatedTenants"
}
aggregatedAssociatedTenantsassociatedTenants$lookup

[Assistant]
Text:have you check the documentation? About half the page starts the examples.
$lookup (aggregation) — MongoDB ManualIt would be better if you give 2-3 sample documents of each collection and your expected output from them. Replace all ObjectId with a number or simple string: {_id:123} or {_id:"abc"} (flexible types). Also add 1-2 more fields if you are not doing full merges. This will enable us to work on real (sample) data and find a solution faster.
Code:{_id:123}{_id:"abc"}

[User]
Text:Yes, I have seen all the examples on the $lookup stage Manual page. That’s how got to try variations on $lookup + $replaceRoot + $mergeObjects + $arrayElemAt. Didn’t help… (I wouldn’t be asking if a haven’t spent a good amount of time reading the docs, looking for answer and trying it on my own first.)Alright, both the user and tenant schemas are exactly as I have them in db and the desired result is also exactly as it should be, I just removed some unrelated fields and ObjectIds for better readability. I can repost it with actual ObjectIds:
User document:Tenant documents:Desired output:I’ve added real ObjectIds. I’ve also added some totally unrelated fields as well (although I don’t see the point - as showcased in the original post, there’s no merge, only adding a new field tenant with the full tenant document next to the tenantId - but in each item of array, that’s the point I can’t seem to get around).Thank you
Code:$lookup$lookup$replaceRoot$mergeObjects$arrayElemAtusertenant{
  "_id": ObjectId("63732cb4919eee473ec5cec7"),
  "email": "user@domain.com",
  "associatedTenants": [{
    "tenantId": ObjectId("636ad8dd185b079cf4cc3014"),
    "role": "foo"
  }, {
    "tenantId": ObjectId("636a8ba3185b079cf4cc3012"),
    "role": "bar"
  }]
}
[{
  "_id": ObjectId("636ad8dd185b079cf4cc3014"),
  "name": "Lorem",
  "domains": [{ "name": "lorem.example.com" }]
}, {
  "_id": ObjectId("636a8ba3185b079cf4cc3012"),
  "name": "Ipsum",
  "domains": [{ "name": "ipsum.example.com" }]
}]
{
  "_id": ObjectId("63732cb4919eee473ec5cec7"),
  "email": "user@domain.com",
  "associatedTenants": [{
    "tenantId": ObjectId("636ad8dd185b079cf4cc3014"),
    "role": "foo",
    "tenant": {
      "_id": ObjectId("636ad8dd185b079cf4cc3014"),
      "name": "Lorem",
      "domains": [{ "name": "lorem.example.com" }]
    }
  }, {
    "tenantId": ObjectId("636a8ba3185b079cf4cc3012"),
    "role": "bar",
    "tenant": {
      "_id": ObjectId("636a8ba3185b079cf4cc3012"),
      "name": "Ipsum",
      "domains": [{ "name": "ipsum.example.com" }]
    }
  }]
}
tenanttenanttenantId

[Assistant]
Text:We have users from all backgrounds and at all levels and we are not psychics, so please bear with us and do not expect anyone to know everything about you at first glance. especially, when you are new to a community, this is something unavoidable.and here is why I had those requests:The solution might come in a very simple form, but I can’t promise I will be the one to deliver it. Also, if you tackle it yourself before we do, please share it with the rest of the community.PS: also in JSON format, it should be {"$oid":"63732cb4919eee473ec5cec7"} to be easily inserted into Atlas to test, for example.
Code:{"$oid":"63732cb4919eee473ec5cec7"}

[Assistant]
Text:Ok, Took me a bit but here it is. As I said, your choice of words, especially “tried everything” confuses us about your level of understanding. So let me explain it so to improve you on what you might have missed on $lookup.And the tricky part is this:PS: a solution to a similar problem seems to exists here: mongodb - $lookup on ObjectId's in an array - Stack Overflow
Code:[
  {
    "$unwind": {
      "path": "$associatedTenants"
    }
  },
  {
    "$lookup": {
      "from": "tenant",
      "foreignField": "_id",
      "localField": "associatedTenants.tenantId",
      "let": {
        "tId": "$associatedTenants.tenantId",
        "tRole": "$associatedTenants.role"
      },
      "pipeline": [
        {
          "$project": {
            "_id": 0,
            "tenantId": "$_id",
            "role": "$$tRole",
            "tenant": "$$ROOT"
          }
        }
      ],
      "as": "associatedTenants"
    }
  },
  {
    "$unwind": {
      "path": "$associatedTenants"
    }
  },
  {
    "$group": {
      "_id": "$_id",
      "associatedTenants": {
        "$push": "$associatedTenants"
      }
    }
  }
]

[Assistant]
Text:Sorry for temporarily deleting my above post, if you were around at that time. It had a hiccup I failed to see.I corrected the problem and edited it. However, keep in mind the solution may not work if you change your field types too far from your example documents. if you will, then follow my explanation to adapt it to new situations or try searching the internet again with your now increased knowledge.
Code:

[User]
Text:You’re amazing. Thank you!  Especially for the explanation, that’s more valuable as I prefer to understand it than just “blindly” solve it.And yeah, you’re right (object ids, additional fields, everything), I’m sorry if I sounded antagonistic or ungrateful… Thanks again for the help.
Code:

[Assistant]
Text:Thanks, as long as we keep understanding of each other, we are cool By the way, I went ahead and asked on another topic if we can do it without $unwind. Though I am a bit lost in the answer, there is another approach you can try (you will need to adapt field names):See you around
Code:

[Assistant]
Text:By the way, I went ahead and asked on another topic if we can do it without $unwind. Though I am a bit lost in the answer, there is another approach you can try (you will need to adapt field names):Similar approach but as per the expected result, you can also use $indexOfArray and $arrayElemAt instead of $filter and $first,Playground
Code:$indexOfArray$arrayElemAt$filter$first$indexOfArraytenantId$arrayElemAtnamedb.users.aggregate([
  {
    "$lookup": {
      "from": "tenants",
      "localField": "associatedTenants.tenantId",
      "foreignField": "_id",
      "as": "tenants"
    }
  },
  {
    "$addFields": {
      "associatedTenants": {
        "$map": {
          "input": "$associatedTenants",
          "in": {
            "$mergeObjects": [
              "$$this",
              {
                "tenant": {
                  "name": {
                    "$arrayElemAt": [
                      "$tenants.name",
                      { "$indexOfArray": ["$tenants._id", "$$this.tenantId"] }
                    ]
                  }
                }
              }
            ]
          }
        }
      },
      "tenants": "$$REMOVE"
    }
  }
])

[User]
Text:Thanks guys!
Both solutions work quite nicely, but think I’ll go with turivishal’s approach as it’s surprisingly simple (and requires slightly less tuning - the need to explicitly select tenant’s fields is also nice as I was gonna $project it anyway).
Code:

[Assistant]
Text:Hey,Thanks for the example. I’m trying something similar, but I need the entire document, not the subset. So in this example, I would need the entire tenant document. I’m just getting to grips with the aggregation pipeline and could do with some help.Appreciated,James
Code:

[Assistant]
Text:I think this is pretty easy, actually. I just use arrayElemAt without the name prefix.
Code:"$arrayElemAt": [
                      "$tenants.name",
                      { "$indexOfArray": ["$tenants._id", "$this.tenantId"] }
                    ]

[Assistant]
Text:H @James_N_A2Here, we use “$project” in the pipeline of the “$lookup” to select fields. If you want the whole document, you can use just a “$match” stage instead, and use the “tenantId” we define by “let” before entering the pipeline.It is also possible without “let” and “pipeline”. check the usual examples for this way.In case you fail, then please open a new topic, give a minimal dataset to try and the expected result, along with what you tried so far, and also put a link to this post so others can see where else you looked.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Missin Realm Constructor error and tags: ['atlas-device-sync', 'react-native']

[User]
Text:Hi, I perfectly followed the instructions that the documentation reported, but every time I start my app it gives me the Missing Realm Constructor error and I don’t understand how to fix it, can you help me thanks. I use all the latest versions of React Native, Realm and Expo
Code:

[Assistant]
Text:@Samuele_Cervietti This typically happens when the Realm .so is not linked into the compiled React Native project.  Verify that pod install has indeed included Realm and do a rebuild of the project.Also I see you are using Expo.  If you are attempting to use the web browser, then this error will also come up, as we are only compatible with Android and iOS.Can you provide a link to the documentation you are following?  I can verify if something is missing.
Code:.sopod installRealm

[User]
Text:@Andrew_Meyer sorry but at the moment i am not home for work, as soon as i come back i will let you know, just one thing but i need to link my react native project with realm? It seemed to me that after version 0.65 it was no longer necessary
Code:

[Assistant]
Text:You won’t have to manually link anything.  Did you follow our Expo documentation?This is based off of a template we created to help get started using Realm in React Native.  Might be a good starting point to figuring out what is happening in your project.
Code:

[User]
Text:I had already created the project for some time, I just wanted to integrate Realm, can you advise me to create a new project and reinstall everything?
Code:

[Assistant]
Text:It should work without creating a new project.  But if you are using expo, you will need to use the expo-dev-client.  This allows you to use 3rd party libraries in an Expo project.  Here’s the getting started documentation.  Once you have that setup, you should be able to use Realm.
Code:

[User]
Text:Hi, I had already tried to use Expo-dev-client but without result, because when I launch the app through “expo start --dev-client” it doesn’t load the app when I try to open it with the expo app on play store
Code:

[Assistant]
Text:Expo-dev-client is not compatible with Expo Go.  You will have to build a dev client and install it on your device.  Have you tried use the a simulator or emulator?
Code:

[User]
Text:I haven’t tried any emulator yet, now I try, in case how do I create a development client? Excuse the many questions but it is the first time that such a thing has happened to me
Code:

[User]
Text:@Andrew_Meyer i tried with the emulator but it keeps giving me the same error ie that the realm constructor is missing. I followed the whole procedure but it didn’t lead to anything, what can I do?
Code:

[Assistant]
Text:It’s hard to say without seeing the exact instructions you are using to install and run your project.  I recommend trying out our expo-template and comparing the project contents to your project once you get that up and running.  Maybe you will be able to find the issue through comparing a working realm project to yours.
Code:

[User]
Text:Okay, I saw that there is also the javascript version, is it okay if I try this? realm-js/templates/expo-template-js at master · realm/realm-js · GitHub
Code:

[User]
Text:I tried to install the Expo templates with realm, but both the typescript and JavaScript templates are not downloaded, when I run the script the download starts and stops almost immediately, creating just the folder, you know how I can
Code:

[Assistant]
Text:Did you follow the instructions in the README?
Code:

[User]
Text:yes i read the documentation on README but it keeps giving me that problem
Code:

[Assistant]
Text:What exact command do you type to produce this error?
Code:

[User]
Text:I tried to install both the typescript and JavaScript template, the commands I used, are these:Typescript:
npx create-react-native-app MyAwesomeRealmApp -t with-realmJavaScript:
expo init MyAwesomeRealmApp --template @realm/expo-template-js
Code:

[Assistant]
Text:And this fails to download the template?  Do other templates (non-realm) work?
Code:

[User]
Text:Executing the above commands does not download the realm model and gives me the error already mentioned, the other models work, also because I only use the default Expo templates (blank). And then I install the packages I need, I had done this for realm too before I knew it was giving an error
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Sudo systemctl start mongod not working and tags: []

[User]
Text:Hello,I installed mongodb according to https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/ on ubuntu 20.04. I adhered the guide and did not change any configuration files or anything else. Now, when I run “sudo systemctl start mongod” the terminal just executes the command but no output is produced. Running “sudo systemctl status mongod” gives:Can somebody tell me what I have done wrong? Many thanks!
Code:mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2022-03-27 15:18:13 CEST; 19s ago
       Docs: https://docs.mongodb.org/manual
    Process: 54971 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
   Main PID: 54971 (code=exited, status=14)

[Assistant]
Text:@peter_parker We may not be able to tell you what’s wrong but the system logs should be able to tell you!cd /var/log and check the syslog and any mongo* logs.
Code:cd /var/log

[User]
Text:Thanks for your answer, it turns out that I had to change the write permission to the /var/lib/mongodb folder
Code:

[Assistant]
Text:Excellent, have fun with MongoDB1
Code:

[Assistant]
Text:┌──(root💀kali)-[/home/stark]
└─# systemctl start mongod.service                                                         3 ⨯┌──(root💀kali)-[/home/stark]
└─# systemctl status mongod.service
× mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: signal) since Mon 2022-05-02 15:57:15 IST; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 2351 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=killed, signal=ILL)
Main PID: 2351 (code=killed, signal=ILL)
CPU: 17msMay 02 15:57:15 kali systemd[1]: Started MongoDB Database Server.
May 02 15:57:15 kali systemd[1]: mongod.service: Main process exited, code=killed, status=4/ILL
May 02 15:57:15 kali systemd[1]: mongod.service: Failed with result ‘signal’.
Code:

[Assistant]
Text:please help me this error show my laptop when i put these command
i used hp8440p laptopi5 i have linux os debian
and i have win10 in my laptop here is work mongo but
not working in my linux os thro me this error please resolve this
Code:

[Assistant]
Text:It terminated with SIGILL it means your CPU is INcompatible with the version of mongod you are trying to use.Search the forum with signal=ILL for potential solution.Thanks @Ramachandra_Tummala for the correction.
Code:

[Assistant]
Text:steevej i think you meant incompatible
Code:

[Assistant]
Text:I don’t understand what want to say
Please answer me in docs type
Code:

[Assistant]
Text:The CPU in your laptop is probably an i5-520M.
That CPU does not support the AVX instruction.
Therefore, it will not run the latest versions of MongoDB.
Code:

[Assistant]
Text:New here so be kind pls.Getting this error when trying to install Mongo 5 on Ubuntu release 20.04 LTS 64.
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: core-dump) since Fri 2023-02-17 22:23:04 EST; 31s ago
Docs: https://docs.mongodb.org/manual
Process: 7221 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=dumped, signal=ILL)
Main PID: 7221 (code=dumped, signal=ILL)Tried to uninstall and reinstall.Output from log:
kernel: [ 3782.753092] traps: mongod[7221] trap invalid opcode ip:555b528a19da sp:7ffca788f9b0 error:0 in mongod[555b4e821000+51e5000]
Feb 17 22:23:04 MobileMoe13 systemd[1]: mongod.service: Main process exited, code=dumped, status=4/ILL
Feb 17 22:23:04 MobileMoe13 systemd[1]: mongod.service: Failed with result ‘core-dump’.
Feb 17 22:25:57 MobileMoe13 PackageKit: daemon quitThanks in advanced.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Setting default values in data schema and tags: ['schema-validation']

[User]
Text:Hello Enthusiast,
I am implementing data schema. Here i have to mention default value to a field of document.is there any possible way to set default value to a field?Best Regards,
M Jagadeesh.
Code:db.createCollection("collect", {
  validator: {
        $jsonSchema: {
            bsonType: "object",
            additionalProperties: true,
            required: ["component", "path"],
            properties: {
                component: {
                    bsonType: "string"
                },
                path: {
                   bsonType: "string",
                   description: "Set to default value"
             }
       }
    }
)

[Assistant]
Text:Hi @Manepalli_Jagadeesh,The schema validation is only intend to enforce/validate a schema definition and not populate values.The server does not have an ability to set default values and we recommend users to set it in their data access application layer or use ODM’s to set those values on the application side.If you use Atlas you can consider having a trigger on the collection to update every inserted document with a specific filed value.Best regards,
Pavel
Code:

[User]
Text:Hi @Pavel_Duchovny,Thank you for information and providing hints to implement default values.Best Regards,
M Jagadeesh.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: allowDiskUse setting in Compass and tags: ['aggregation', 'compass']

[User]
Text:Hello.
I’m trying to build a view using Compass aggregation builder. I want to use $ group. Due to the size of the source collection, I  need to add {allowDiskUse: true} to the aggregation pipeline.  How and where can I set this parameter using Compass?
Thank you in advance for your help,
Regards,
Marek
Code:

[Assistant]
Text:Hi @Marek_Bisztyga,Welcome to MongoDB community!Compass allows you to use a sample mode in the aggregation builder therefore you should be able to construct your pipeline in compass and use the “export” button in the end.Only in 4.4 you can add the allowDiskUse is allowed in find.The  {allowDiskUse: true} should be added to the query/aggregate command used on the already defined view therefore it cannot be done as part of the agg builder.Hope that helps.Best
Pavel
Code:{allowDiskUse: true}

[User]
Text:The {allowDiskUse: true} should be added to the query/aggregate command used on the already defined view therefore it cannot be done as part of the agg builder.Hi @Pavel_Duchovny
To add {allowDiskUse: true} to an already defined (through the aggregate command)  view, I have to define the view first, and I cannot do this because to define it I have to add {allowDiskUse: true}.
Is my reasoning correct?
Best
Marek
Code:{allowDiskUse: true}

[Assistant]
Text:Hi @Marek_Bisztyga,Not necessarily. You can attempt the following:Create view with pipeline without the allowDiskUse, example:The view only consume the data when you query it. Here you can use the allowDiskUse:
Prior 4.4 -From 4.4 you can use find:Thanks
Pavel
Code: db.createView("myView", "myColl" ,  [ { $group : {"_id" : "$id" , arr : { $push : "$value" }} }])
db.myView.aggregate([],{allowDiskUse : true });
 db.myView.find({},{},{allowDiskUse : true })

[User]
Text:Hi  Pavel.
It works.
Now I have to figure out how to make the Tableau, which is supposed to see this view,  work the same way.
Thanks for the help.
Best,
Marek
Code:

[Assistant]
Text:Hi @Marek_Bisztyga,How do you connect to tableau? If its through the BI connector it always set allowDiskUse option on . So it should work:Best
Pavel
Code:

[User]
Text:Hi @Pavel_Duchovny
Oh! Great news!
Thank you.
Code:

[Assistant]
Text:Hello,I have exactly the same issue, but I’m afraid I still haven’t managed to resolve it. When I try to use find with {},{},{allowDiskUse : true } on my view in Compass, I get the same error.Any chance you could help me out with this please?Thanks a lot,
Emily
Code:

[Assistant]
Text:Welcome to the MongoDB Community Forums @jamiesone!Please provide some more details on the issue you are encountering:Thanks,
Stennie
Code:

[Assistant]
Text:Thank you for your reply!I have exactly the same issue as the other post in this thread. I’m using the Compass aggregation builder to run a long pipeline including $group which previously worked, but now gives me the error
Code:

[Assistant]
Text:ah sorry I can’t work out how to edit my previous post…It now gives me the error “PlanExecutor error during aggregation :: caused by :: Exceeded memory limit for $group, but didn’t allow external sort. Pass allowDiskUse:true to opt in.”I tried filtering the view as you suggested,{},{},{allowDiskUse : true }But it gives me the same error.I’m using Compass version 1.20.5 and the deployment is a MongoDB 5.0.2 Community on a kubernetes clusterThanks again,
Emily
Code:{},{},{allowDiskUse : true }

[Assistant]
Text:Hi @jamiesone ,
I honestly don’t recall how to pass that in compass.Can you build aggregation and run it with this setting in the shell tab?Thanks
Pavel
Code:

[Assistant]
Text:Thanks for your reply! Yes, it definitely works in the shell once I’ve added the allowDiskUse setting. But we’d really like to find out how to enable this setting in Compass if possible as my colleague then runs a whole lot of other filters on the view, so it’s really practical to be able to do this in Compass.Thanks again,
Emily
Code:

[Assistant]
Text:Hi @jamiesone ,Are you working with atlas? If yes what instances?Compass should add this by default…
Code:

[Assistant]
Text:Hello,No, I’m not working with Atlas, I’m using MongoDB 5.0.2 Community on a kubernetes cluster.It seems like the functionality was added at some point?
https://jira.mongodb.org/browse/COMPASS-2722Thanks again for your help,
Emily
Code:

[Assistant]
Text:Hi Emily. I am having the exact same problem. I follow the instructions line by line but at the end of it I only get an empty view. How did you solve it?
Code:

[Assistant]
Text:Hi Marek!Have you found a way to solve this?
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Where is the password for the cluster? and tags: []

[User]
Text:I can’t find it anywhere in settings.
The UI for mongodb is the most confusing of anything I’ve ever seen.
Code:

[Assistant]
Text:Hi @Alan_c, welcome to the community.
You can manage Atlas Users by clicking on the Database Access link in the sidebar under the security section.
|625.1067961165048x2521022×412 45.4 KB
After clicking on the link, you would see an interface like this:
|624x187, 100%.00267276495391600×479 88.6 KB

Also, we have already discussed this question in our FAQ post, please take a look at question no. 6 for more information.In case you have any doubts, please feel free to reach out to us.Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer
Code:

[Assistant]
Text:The password tho? Where exactly could it be retrieved?Regards,
Marcelino
Code:

[Assistant]
Text:You cannot retrieve the password
If you forgot the dbuser password edit the user and change the password as shown in the above snapshots
or create a new user with add new database user link
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: com.mongodb.MongoSocketOpenException: Exception opening socket and tags: []

[User]
Text:Hi All,Sometimes for one hour we are having connection issue  in between Spring BootApplication 2.0.0 Release version with Mongo Db Java driver 3.11.1.
Application is deployed in Azure App service.It works good but  some of the requests are getting below issue.Please let me know if anyone have similar issue.
Code:com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-3.11.1.jar!/:na]
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongodb-driver-core-3.11.1.jar!/:na]
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-3.11.1.jar!/:na]
	at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
Caused by: java.net.SocketTimeoutException: connect timed out
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:na]
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:na]
	at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:na]
	at java.base/java.net.SocksSocketImpl.connect(Unknown Source) ~[na:na]
	at java.base/java.net.Socket.connect(Unknown Source) ~[na:na]
	at java.base/sun.security.ssl.SSLSocketImpl.connect(Unknown Source) ~[na:na]
	at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) ~[mongodb-driver-core-3.11.1.jar!/:na]
	at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-3.11.1.jar!/:na]
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-3.11.1.jar!/:na].

[Assistant]
Text:Hi @vamsi_krishna welcome to the community!It seems that the error was a connection time out from the java.net side and not from the MongoDB driver particularly. I’m not sure why this is so, since the reason may be specific to Azure App Service.Do you see a similar issue when not using the App Service? Also, it could be a limitation of certain pricing tier. Have you tried using a higher tier and see a similar failure?Best regards,
Kevin
Code:java.net

[User]
Text:@Kevin.
Thank you for responding to my query.
Yes, we are seeing this issue in Azure APP service.  It is working good in local system.
Regarding app service plans. Sure, will check that one.Thank you.
Code:

[User]
Text:@kevinadiWe are using  Production P2V2 App Service Plan in Azure.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Intermediate MongoTimeoutError: Server selection timed out after 30000 ms and tags: ['node-js', 'mongoose-odm']

[User]
Text:We are seeing intermediate issue of pod crashing with error stating MongoTimeoutError: Server selection timed out after 30000 ms when it is trying to connect mongoDb. On replacing the pod it is able to connect successfully. If we again try to replace the running pod we see above error. It is intermediate, could anyone help us here. Mongoose version used is 5.8
Code:

[Assistant]
Text:When you say pod are you referring to K8s?
Code:

[User]
Text:yes @Andrew_Davidson
Code:

[User]
Text:We have whitelist of all ip via 0.0.0.0 is in place and we use a m30 clusterBelow is the code snippet which we are using to connect mongo atlasmongoose version:  “mongoose”: “5.8.7”
mongo: 4.2.21<<<<< code >>>>>var options = {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify:false,
connectTimeoutMS: 300000,
socketTimeoutMS:0 ,
keepAlive: 1
};mongoose.connect(“connection string”, options, function (err) {
if (err) {
logger.critical("Error while connecting to mongoDB … ", err);
} else {
logger.info(“mongodb connected successfully.”)
}
});
Code:let db = mongoose.connection;
db.once('open', function () {
  logger.info('MongoDB event open');
  db.on('connected', function () {
    logger.info('MongoDB event connected');
  });

  db.on('error', function (err) {
    logger.info('MongoDB event error.: ' + err);
  });
});

[User]
Text:Tested above code with mongoose version 6.5.x with the above code snippetvar options = {“ssl”:true,“sslValidate”:false,“useNewUrlParser”:true,“useUnifiedTopology”:false,“keepAlive”:1,“connectTimeoutMS”:300000,“socketTimeoutMS”:0}Error while connecting to mongoDB … may be down Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist: https://docs.atlas.mongodb.com/security-whitelistMongoDB event error.: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/Basically with both version 5.8 and 6.5 we are facing similar issue just that error message are different , could any one help us here who has faced these issues
Code:

[Assistant]
Text:It’s not going to be any kind of configuration if it’s intermittent like this.Are there any other suspicious events in the time before it crashes? Have you check the logs for the pod?
Code:

[User]
Text:@Dan_Mckean we don’t see any suspicious things , we are only seeing below error in the log

Screenshot 2022-08-01 at 2.08.20 PM3584×188 38.7 KB

Screenshot 2022-07-29 at 7.41.05 PM3158×152 34.1 KB
Error while connecting to mongoDB
may
be down Could not connect to any servers in your MongoDB Atlas cluster.
One common reason is that you’re trying
to
from an IP that isn’t whitelisted. Make sure vour current IP address is on vour Atlas cluster’s IP whitelist: httos://docs.atlas.monaodb.com/securitv-whiteli
14:05:26.446Z] [INFO]: [BPA] [cisco-bpa-platform/mw-backup-restorel [ServerName: bpa-ns] [PodName: backup-restore-service-5fb4d8f4dc-bm9vv] [session-id: 1 [c
10DB event error.: MonaooseserverselectionError: Could not connect to anv servers in vour MonaoDB Atlas cluster. One common reasonWe try to open multiple concurrent connections is that any concerns here ?
Code:

[Assistant]
Text:We try to open multiple concurrent connections is that any concerns here ?I think it probably depends on how many multiple is…! I’m not sure of the limits but I’m sure it’s fine for sensible numbers.My suggestion would be to open a support case (top right in Atlas) and see if our support folks can help take a look at things from the Atlas end of things. Perhaps we have some logs on that end.
Code:

[User]
Text:@Dan_Mckean @Andrew_DavidsonOn further investigations below are the observationsSince this issue is reproducible all over the time, we tried packet capture between working pod and non working pod [both of same deployment version], the observation here is in the non working scenario, after the client makes TCP connection it tries to perform TLS client hello but the pod is not getting reply from the mongodb server resulting in timeout and repeated retries. In all retries the TLS client hello is sent but mongodb server is not replying back.We further did a deep dive analysis on the packet capture and found that, when the client is making “Client Hello”, for working pods its taking TLSv1.2 protocol and in a non working its using TLSv1 protocol layer…It is very intermediate, application fails to get connection with TLS1.0 , but with TLS1.2 is able to connect successfullyIn mongo db atlas we have set TLS  1.0 and above , still the pod crashes when at run time TLS1.0 gets used.Could someone help us here , we are clueless how to go ahead
Code:

[Assistant]
Text:Good find Is there any possibility of configuring your application to consistently use TLS1.2? That would be the ideal for security reasons.And did you enable it by editing the deployment configuration and changing it as follows?

image855×307 44.3 KB
But yes, in theory Atlas can still support TLS1.0 - if that’s been enabled in the cluster settings (as above) but it’s not being accepted for those incoming connections I’d suggest opening a support case (top right in Atlas) and see if our support folks can help take a look at things from the Atlas end of things.
Code:

[User]
Text:@Dan_Mckeanyes we have enabled deployment configuration from day 1 here is screen shot for the same

image1756×560 76 KB
In that scenario it should work right with TLS1.0, and from the application we are not setting TLS version, could be mongoose driver [5.8.7]  thats using it at runtime. Is there a way we could set TLS version when we try to connect via mongoose?Below is the TCP dump for working pod

image1508×478 92.6 KB
Below is the TCP dump for non working pod

image1246×447 50.5 KB

Code:

[Assistant]
Text:Sorry - we’ve reached the limits of my ability to help in this area.Are you able to open a support case so that someone can help diagnose why TLS1.0 isn’t working as it should?
Code:

[User]
Text:@MaBeuLux88 could you help us here, we are currently clueless
In addition to above issue mentioned we see in logsmongoose connect(…) failed with err:  MongoNetworkError: failed to connect to server [hostname:27017] on first connect [Error: read ETIMEDOUT
at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)
at TLSWrap.callbackTrampoline (internal/async_hooks.js:130:17) {
name: ‘MongoNetworkError’,
[Symbol(mongoErrorContextSymbol)]: {}
}]
at Pool. (/home/node/app/node_modules/mongodb/lib/core/topologies/server.js:433:11)
at Pool.emit (events.js:400:28)
at /home/node/app/node_modules/mongodb/lib/core/connection/pool.js:577:14
at /home/node/app/node_modules/mongodb/lib/core/connection/pool.js:1021:9Clearly says its a TLS issue , can some one help us here
Code:

[Assistant]
Text:Hey all,I read the thread in diagonal but looks like you two have been pretty far in the debugging already. I’d try to use the latest versions (both for Mongoose and MDB) to see if that solves the problem. I’d also try to update & upgrade the OS (linux?) running the pods and make sure they are using the latest libssl package or equivalent.Else open a ticket because it could also be a weird bug that needs proper investigation from the Atlas team.Cheers,
Maxime.
Code:

[User]
Text:Hey @MaBeuLux88In addition to above issue we noticed below error , noting hostname of one of the primary is getting printed with error MongoNetworkError. Could you please look into these logsWe have also raised case, its been 48 hrs no help from the support team
Code:[2022-08-05T15:37:59.091Z] [INFO]: [] [platform/activation] [ServerName: ns] [PodName: 7cbb8b8c69-rp9wn] [session-id: ] [correlation-id: ] MongoDB event error.: MongoNetworkError: failed to connect to server [secondaryHostname:27017] on first connect [MongoNetworkError: connection 5 to <<secondaryHostname>>:27017 timed out
    at TLSSocket.<anonymous> (/home/node/app/node_modules/@platform/common-app/node_modules/mongodb/lib/core/connection/connection.js:355:7)
    at Object.onceWrapper (events.js:519:28)
    at TLSSocket.emit (events.js:400:28)
    at TLSSocket.Socket._onTimeout (net.js:495:8)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  [Symbol(mongoErrorContextSymbol)]: {}
}]

[2022-08-05T15:37:59.208Z] [INFO]: [] [platform/activation] [ServerName: ns] [PodName: -7cbb8b8c69-rp9wn] [session-id: ] [correlation-id: ] MongoDB event error.: MongoNetworkError: failed to connect to server [<<primaryHostname:27017] on first connect [MongoNetworkError: connection 5 to primaryHostname:27017 timed out
    at TLSSocket.<anonymous> (/home/node/app/node_modules/@-platform/-common-app/node_modules/mongodb/lib/core/connection/connection.js:355:7)
    at Object.onceWrapper (events.js:519:28)
    at TLSSocket.emit (events.js:400:28)
    at TLSSocket.Socket._onTimeout (net.js:495:8)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  [Symbol(mongoErrorContextSymbol)]: {}
}]


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: mongod.service Failed with result core-dump and tags: []

[User]
Text:Hi Mongodb OPS and Sysad,I’m new to mongodb and currently working on a virtual machine installed with redhat. it happens that we tried to change the permission of the following while adding the keyfile on the security option under /etc/mongod.confthen we restart the mongodb using the command systemctl restart mongodhere’s the error:● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor pres>
Active: failed (Result: core-dump) since Wed 2021-02-24 13:41:34 PST; 1 day >
Docs: https://docs.mongodb.org/manual
Process: 1279 ExecStart=/usr/bin/mongod $OPTIONS (code=dumped, signal=ABRT)
Process: 1277 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited,>
Process: 1274 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (cod>
Process: 1271 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, s>mongod[1279]:  mongod(_ZN5mongo11Initial>
mongod[1279]:  mongod(_ZN5mongo21runGlob>
mongod[1279]:  mongod(+0xD9DF2A) [0x560b>
mongod[1279]:  mongod(+0xD1F719) [0x560b>
mongod[1279]:  libc.so.6(__libc_start_ma>
mongod[1279]:  mongod(_start+0x2E) [0x56>
mongod[1279]: -----  END BACKTRACE  -----
systemd[1]: mongod.service: Control proc>
systemd[1]: mongod.service: Failed with >
systemd[1]: Failed to start MongoDB Data>I tried to uninstall using this command below:sudo service mongod stop
sudo apt-get purge mongodb-org*Remove Data Directories.
Remove MongoDB databases and log files.sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodbAnd fresh install mongodb to another version same thing happened error message didn’t disappeared and mongodb service failed to start.Mongodb Current Version: MongoDB shell version v4.2.8
OS: Red Hat Enterprise Linux release 8.2 (Ootpa)Hoping from this forum someone can help me on this issue  and able to share some ideas to fix it. Thank you in advance.
Code:

[Assistant]
Text:@Ian_Sherwin_Canaya  Do you get the solution for this issue ? I have also this issue i can’t get solution yet…if you get the solution please give the method…
Code:

[Assistant]
Text:Hi @Ian_Sherwin_Canaya and @ajay_ps, even I’m new to MongoDB and I too had this error or whatever we can call this. I searched a ton of communities and was unable to find a fix and at the end came to a decision of reinstalling MongoDB from scratch by first removing all the packages and directories like log, database etc. After reinstalling it works fine.About the error:
I have encountered two types of similar errors so far. One is similar to the one talked about in this post Active: failed (Result: core-dump) for which only fix I could find was to reinstall from scratch. I read somewhere that this is a possible consequence of crashed or corrupted database which can be caused by terminating the database in a way which shouldn’t be used ( I have no idea what way is it).Another similar error is Active: failed (Result: exit-code). This can be caused by various correctable reasons like ownership (chown) or rwx (chmod) permissions of the log file and dbpath, the mongod service not running, etc.I hope someone would find this information useful
Code:Active: failed (Result: core-dump)Active: failed (Result: exit-code)

[Assistant]
Text:@Yashvander_Bamel  I reinstalled many times after deleting all packages. But No solution. and i changed the user in ubuntu and again installed but no solutions.
Checking time “sudo systemsctl start mongod” and after “mongo” command then get the error. Illegal instruction (core dumped)… this is the main issue
I can’t get any solution yet…
Code:

[Assistant]
Text:Did mongodb work on your system even once? Did you get this error when you installed mongodb for the first time ever? If that’s the case I can not comment anything.But if it did run once and then crashed, you can remove all the packages and use steps mentioned here and delete all the files associated with mongodb. And then try to reinstall. Note that this would work only if you could run mongodb atleast once on your system as far as I can tell. But you can try in the other case as well.And once you reinstall mongodb again, do not forget to change the ownership and permissions of the log and data folders
Code:

[Assistant]
Text:Found this on StackOverflow, very underrated answer. The KVM processor used in most Linux VM environments is NOT COMPATIBLE with MongoDB, try to change it to something else. I use Proxmox, and when I changed from KVM processors to EPYC it worked right away, no changes.
Code:

[Assistant]
Text:how do you change it? can you tell me?
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: I cannot MongoDB on Ubuntu 22.04 LTS and tags: []

[User]
Text:Greetings.I want to install mongoDB but I cannot. I tried it at Oracle cloud, Ubuntu 22.04 LTS. I tried to follow this, but error occurs in last command(sudo apt install mongodb-org).

스크린샷 2022-08-16 14-35-17866×614 109 KB

I tried to sudo apt install libcurl1.1, but it occurs Error: E: Package ‘libssl1.1’ has no installation candidate.How can I install MongoDB in Ubuntu 22.04 LTS? I cannot downgrade my instance’s OS.
Code:

[User]
Text:PS. I founded ‘E: Unable to correct problems, you have held broken packages.’ and why this error occurs.I tried to sudo apt install libcurl1.1, but it occurs Error: E: Package ‘libssl1.1’ has no installation candidate.this is that’s solution.
Code:

[Assistant]
Text:Check this link
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: DeprecationWarning: Mongoose: the `strictQuery` and tags: ['node-js', 'mongoose-odm']

[User]
Text:hi
i am reciving thiss error while i try to connect to mongo db using mongooseBlockquote
(node:20404) [MONGOOSE] DeprecationWarning: Mongoose: the strictQuery option will be switched back to false by default in Mongoose 7. Use mongoose.set('strictQuery', false); if you want to prepare for this change. Or use mongoose.set('strictQuery', true); to suppress this warning.i need to know what are the strictQuery and why i am getting this error
Code:strictQueryfalsemongoose.set('strictQuery', false);mongoose.set('strictQuery', true);

[Assistant]
Text:Hello @mina_remon ,Welcome to The MongoDB Community Forums! Schemas have a few configurable options which can be passed to the constructor or to the set method:When strict option is set to true , Mongoose will ensure that only the fields that are specified in your Schema will be saved in the database, and all other fields will not be saved (if some other fields are sent). In simple term, the strict option, ensures that values passed to our model constructor that were not specified in our schema do not get saved to the db. Mongoose supports a separate strictQuery option to avoid strict mode for query filters. This is because empty query filters cause Mongoose to return all documents in the model, which can cause issues.To learn more about these options, please go through Mongoose v6.9.0: Schemas.Regards,
Tarun
Code:setnew Schema({..}, options);

// or

const schema = new Schema({..});
schema.set(option, value);
strictstrictQuery


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Realm schema for different object types in array and tags: ['graphql']

[User]
Text:HiEDIT: For clarity I have explained this as different object types in array instead of multiple types per field.NOTE: In the case of different scalar types in the same field there is an outstanding issue with GraphQL (not Realm GraphQL) to have this supported in GraphQL schemas see Additional Note 1 below.Environment:MongoDB Atlas cluster running MongoDB 4.4
MongoDB Realm connected to clusterIssue:I am trying to configure a Realm schema and Realm GraphQL (and later Sync) to support data where an array of objects can contain different objects, regardless of what I try I am unable to generate/create a valid schema that reflects the data and also works for Realm GraphQL.I am investigating and asking for help in case anyone else has a solution or potential solution that could be implemented in Realm GraphQL.What I am trying to achieve:The problem:Here is a simplified sample of the data I am trying to model, specifically the “results” array should be capable of accepting different “result” objects, and ideally each “result” object should be unique with respect to “type”. (see Additional Note 2 below for alternate data structure)What I have tried so far:1 - I have inserted the typed data into a MongoDB collection:
data1390×560 61.2 KB
2 - I have written a MongoDB collection validation using json schema which validates the data, note the use of an array of bsonType for “value”:The following MongoDB collection validation also validates, note the use of anyOf to validate each “results” item:3 - I then use Realm to generate a schema from the data (Realm → Schema → select collection → Schema tab → Generate Schema), Realm suggests the following schema - note that the bsonType suggested is the first type in the array - in this case int, but if a different type was first in the array the generator would suggest that but not multiple types.
NOTE: you can set the bsonType to string which will allow a Realm GraphQL query to return the data as strings but not the type, this also means that mutations are not strongly typed and do not accept int or double values as desired.4 - This schema is accepted by Realm GraphQL (no warnings) but when a query is run the results are not correct - note that the string value is returned as null and the double value has been truncated:GraphQL query run in GraphiQL:Result:5 - If I try to modify the Realm schema to match the data using an array of bsonTypes as suggested by the Realm documentation specifically in the note:The fields available in a JSON schema object depends on the type of value that the schema defines. See the document schema types reference page for details on all of the available schema types.that links to this documentation and shows “The following fields are available for all schema types” should accept an array for bsonType:The Realm schema should become:however this Realm schema causes Realm GraphQL to show a warning:results.value	InvalidType	error processing “type” property in JSON Schemaand trying to run a query returns an error:GraphQL query run in GraphiQL:Result (error):6 - I have also tried generating a valid JSON Schema using online tools and by manually constructing a schema, in these cases the tools sometimes suggest the use of “anyOf” however in each instance even if the schema is accepted by Realm it still shows the same GraphQL Schema generation warning.Latest / TLDR:Based on my investigation and the information about GraphQL union types described in the GraphQL GitHub issues it should be possible to use a union type in the Realm GraphQL schema to handle different objects nested in arrays.In the GraphQL schema:However I cannot see any way to customise the Realm GraphQL schema - there is an open issue to allow custom Realm GraphQL schema - please vote for this:Dear MongoDb GraphQl Stitch developers,

Is it possible to add an ability to modify the final GraphQl schema (in order to remove unnecessary for my API stuff)
OR
Build it based on existed roles?

For example, Im building a "read only" GraphQl API and...
.
.Additional:Additional Note 1:I have found there is a GraphQL proposal to support multiple scalar types in fields, for example using a string or double for the same field: Proposal: Support union scalar types #215This is so that for the data:you could specify a GraphQL schema:Currently it seems a workaround is to define a ‘union’ type in GraphQL and then use that union type rather than scalar types:For example in GraphQL:Additional Note 2:If possible each “result” object should contain similar field names, however if this causes problems
the data could be modelled with each object having different field names, for example:
Code:{
  "name": "This is a text string",
  "results": [
    { "type": "count", "value": 12, "unit": "items" },
    { "type": "comment", "value": "A text comment", "unit": "n/a" },
    { "type": "weight", "value": 56.69, "unit": "kg" }
  ]
}
{
  $jsonSchema: {
    bsonType: "object",
    properties: {
      _id: { bsonType: "objectId" },
      name: { bsonType: "string" },
      results: {
        bsonType: "array",
        items: {
          bsonType: "object",
          properties: {
            type: { bsonType: "string" },
            value: { bsonType: [ "string" , "int", "double" ] },
            unit: { bsonType: "string" }
          }
        }
      }
    }
  }
}
{
  $jsonSchema: {
    bsonType: "object",
    properties: {
      _id: { bsonType: "objectId" },
      name: { bsonType: "string" },
      results: {
        bsonType: "array",
        items: {
          anyOf: [
            {
              bsonType: "object",
              properties: { type: { bsonType: "string" }, value: { bsonType: "string" }, unit: { bsonType: "string" } }
            },
            {
              bsonType: "object",
              properties: { type: { bsonType: "string" }, value: { bsonType: "int" }, unit: { bsonType: "string" } }
            },
            {
              bsonType: "object",
              properties: { type: { bsonType: "string" }, value: { bsonType: "double" }, unit: { bsonType: "string" } }
            }
          ]
        }
      }
    }
  }
}
{
  "title": "example",
  "properties": {
    "_id": { "bsonType": "objectId" },
    "name": { "bsonType": "string" },
    "results": {
      "bsonType": "array",
      "items": {
        "bsonType": "object",
        "properties": {
          "type": { "bsonType": "string" },
          "unit": { "bsonType": "string" },
          "value": { "bsonType": "int" }
        }
      }
    }
  }
}
query { example { _id name results { type unit value } } }
{
  "data": {
    "example": {
      "_id": "60755d9c0000b6ffe15cf906",
      "name": "This is a text string",
      "results": [
        { "type": "count", "unit": "items", "value": 12 },
        { "type": "comment", "unit": "n/a", "value": null },
        { "type": "weight", "unit": "kg", "value": 56 }
      ]
    }
  }
}
  ...
  "bsonType": "<BSON Type>" | ["<BSON Type>", ...],
  ...
{
  "title": "example",
  "properties": {
    "_id": { "bsonType": "objectId" },
    "name": { "bsonType": "string" },
    "results": {
      "bsonType": "array",
      "items": {
        "bsonType": "object",
        "properties": {
          "type": { "bsonType": "string" },
          "unit": { "bsonType": "string" },
          "value": { "bsonType": [ "string", "int", "double" ] }
        }
      }
    }
  }
}
query { example { _id name results { type unit value } } }
{
  "data": null,
    "errors": [
    {
      "message": "Cannot query field \"value\" on type \"ExampleResult\".",
      ...
    }
  ]
}
type CustomTypeComment { type: String, value: String, unit: String }
type CustomTypeCount { type: String, value: Int, unit: String }
type CustomTypeWeight { type: String, value: Double, unit: String }
union CustomResultType = CustomTypeComment | CustomTypeCount | CustomTypeWeight

type Event { id: String!, name: String, results: [CustomResultType] }
[
  { "_id": "...", "multi": "A string" },
  { "_id": "...", "multi": 10.25 },
]
...
field: Int | String
...
type CustomTypeOne { id: Int, value: String }
type CustomTypeTwo { id: Int, value: Int }
union CustomType = CustomTypeOne | CustomTypeTwo

type Event { id: Int!, results: [CustomType] }
{
  "name": "This is a text string",
  "results": [
    { "type": "count", "count": 12, "unit": "items" },
    { "type": "comment", "comment": "A text comment" },
    { "type": "time", "time": 5600, "unit": "s" }
  ]
}

[Assistant]
Text:Did you found any solution for this ? I am also facing the same issue with Realm.
Code:

[User]
Text:Edit - details moved to original post.
Code:

[Assistant]
Text:We don’t currently support a union of scalar types in our default GraphQL service to stay as close to the spec as possible. That being said, there is a workaround to achieve something similar by setting the schema of the field like so:{ "field": { "anyOf": [{ "type": "string" }, { "type": "null" }] } }The generated schema will ignore this field, but it can still be accessed via the custom resolver, (likely by having to define two different types).
Code:{ "field": { "anyOf": [{ "type": "string" }, { "type": "null" }] } }

[User]
Text:Hi SumedhaI tried using anyOf in my Realm schema you suggested:As expected the Realm GraphQL still gives me a schema error and ignores the field:Can you explain how I can access the collection using a custom resolver / define two different types
Code:{
  "title": "example",
  "properties": {
    "_id": { "bsonType": "objectId" },
    "name": { "bsonType": "string" },
    "results": {
      "bsonType": "array",
      "items": {
        "bsonType": "object",
        "properties": {
          "type": { "bsonType": "string" },
          "value": { "anyOf": [{ "type": "string" }, { "type": "null" } ] },
          "unit": { "bsonType": "string" }
        }
      }
    }
  }
}
Field Path     Error Code         Message
results.value  MissingSchemaType  error processing "type" property in JSON Schema

[Assistant]
Text:{ “anyOf”: [{ “type”: “string” }, { “type”: “null” }] }Hi @Sumedha_Mehta1. I tried your recommendation but it doesn’t seems to be working. Below is the schema that I am using:And following is the error I am getting when generating Realm Data ModelsScreenshot 2021-04-13 at 9.25.29 PM1864×644 65.8 KB
Code:{
 "title": "BuildingEquipment",
 "properties": {
    "_id": { "bsonType": "objectId"},
    "configs": {
       "bsonType": "array",
       "items": {
          "bsonType": "object",
          "properties": {
             "field": {"bsonType": "string"},
             "value": { "anyOf": [{"bsonType": "string"}, {"bsonType": "double"}]}
          }
       }
     }
  }
}

[Assistant]
Text:@Dhananjay_PugliaAre you using Sync in this application? That error refers to that service specifically, not GraphQL. GraphQL will just ignore that field in your schema.
Code:

[Assistant]
Text:@Sumedha_Mehta1 Yes I am using Sync in this application. Will this solution not working with Sync? If no then is there any way where I can sync multiple type of data for a single field ?
Code:

[Assistant]
Text:We are working on a way to to introducing this for Sync pretty soon (~1 mo) - you can stay up to date on new data types by subscribing here: Realm Community Projects | Realm.io
Code:

[Assistant]
Text:Great. Thanks a lot @Sumedha_Mehta1 for the update.
Code:

[Assistant]
Text:I see that the “mixed” type has now been added to Realm DB / Sync – I presume this would now enable you to implement union types in GraphQL? Or has it already been done? @Sumedha_Mehta1
Code:

[Assistant]
Text:Is there any progress on this subject?
Code:

[Assistant]
Text:You can apply multiple types to a field in the schema like this [“string”, “null”].
Refer: https://docs.mongodb.com/realm/schemas/types/
img: https://i.imgur.com/vulUoem.pngBut those type will be ignored by the graphql schema generation.
Refer: https://docs.mongodb.com/realm/graphql/types-and-resolvers/
img: https://i.imgur.com/eXxqljz.pngcurrently I cant find a workaround for this.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Restricting user to login from multiple devices and tags: ['app-services-user-auth']

[User]
Text:As per my use case, I need to restrict my end-user to login from single device. I want to implement any one of the following. Assume end-user is already logged in from one device. When user tries to login from second deviceAny of these approach will help me to implement my use case.Thanks
Code:

[Assistant]
Text:Hey Sudarshan -The general approach would be:a) Store the user’s “currentDeviceId” every time the user logs in with Custom Function Authentication and Custom User Datab) The next time the user logs in, revoke all sessions from the Admin API in your custom function, before logging them again and setting the user’s new Device ID - this way you get to add your session expiration logic before the user has actually logged in on another device and provided another session token.c) Add client code to handle invalid session requests  and take user to logout screenIn practice, this would look like:
device a → logged in
device b → calls login function → -> revokes all sessions and invalidates device a → logs user in from device b with new session → user is logged in on device b successfullyany subsequent request will fail, client code handles invalid session and takes user to login screenIf you want to request more session/token configuration options - you can add a request here. We use items here to influence our roadmap on Realm.Sumedha
Code:

[User]
Text:Thanks for such a detailed approach.Can you please let me know the structure of the parameter, i.e., loginPayload of Custom Function Authentication.
Code:loginPayload

[Assistant]
Text:The function payload will be whatever custom credentials you want to pass in for authentication (e.g. email, password, device Id, etc)There is an example on one of our DevHub posts on how to use Custom Function Auth
Code:

[Assistant]
Text:Hi  Sumedha ,
Mentioned DevHub posts
is not available (404-Not Found). Can please check it once.
Code:

[Assistant]
Text:A quick search on the MongoDB Developer site returns this article has has the same title. I’m pretty sure that MongoDB changed their site around a bit not that long ago so it makes sense that articles were moved to the new location.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Default "number" to double "Double" type and tags: ['node-js']

[User]
Text:Right now, when I insert a new document from nodejs, number properties are inserted depending on the most fitting type, so 0 are inserted as Int32 but 0.1 as Double.In mongo shell types are defaulted to Double. Is there any way to default all numbers to Double in mongodb nodejs driver? This is giving me some schema validation problems and don’t wall to fill my entire back-end with "new Double()"s.
Code:

[Assistant]
Text:Hello @Jorge_Fuentes, welcome to the MongoDB Community forum.What you are saying is correct about the different types for the numbers with NodeJS driver. Can you tell how are you inserting the documents into the collection - I mean the code you are using to insert.
Code:

[Assistant]
Text:Hi @Jorge_Fuentes, welcome onboard!You need to “cast” your value so they are actually Double in JS.Thanks JS for not being a typed language .Cheers,
Maxime.
Code:Doublevar Double = require("mongodb").Double;
var foo = Double(15)

[Assistant]
Text:An option is to use a ODM like Mongoose, where you can define a schema with field types. This might work.Here is another possibility - you can define a custom number class which is used throughout the application. This will make sure that the number data is of one specific type (as needed for specific field or fields). This is not an unusual solution. I have studied such solutions for object-oriented applications (e.g., using Java) where a separate class, for example, to represent currency numbers.
Code:

[User]
Text:Well, I was thinking about a config parameter under the driver options (if it exists), more than using a ODM or redoing part of the backend. As I already said, I don’t want to add Doubles all around the backend when I’m going to work with numbers. Just love to work with plain js.mongo shell has, as per documentation (https://docs.mongodb.com/manual/core/shell-types/), Doubles as default, so I thought that the “convert to the most-fitting” was a driver thing, not a mongo one. If I have to redo part of the backend I prefer the casting thingy.What I’m using to work with the database are the typical insertOne, updateOne, updateMany, etc… for example, one item with a property that starts at zero, I now use insertOne({...yadayada, prop: new Double(0)}), which I would like to be insertOne({...yadayada, prop: 0}). I just like to have the less conversion-code or less non-vanilla code as possible. I like to see it as plain as possible.Thank you for your help!
Code:insertOneupdateOneupdateManyinsertOne({...yadayada, prop: new Double(0)})insertOne({...yadayada, prop: 0})

[Assistant]
Text:@Jorge_Fuentes Did you ever find a solution? I’d like to do the same.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: ObjectId in must be a single string of 12 bytes or a string of 24 hex characters on reloading the product page and tags: ['node-js', 'atlas-functions']

[User]
Text:Hey there everyone,
I was following the jumpstart ecommerce tutorial with mongo db, and I encountered this problem.When I click on the card and go to the product page it works fine, but when i reload the product page it returns an error:`Error: ObjectId in must be a single string of 12 bytes or a string of 24 hex charactersThe realm function for getting the product:Thank you for taking your time out to read this question.Jumpstart https://www.youtube.com/playlist?list=PL4RCxklHWZ9v2lcat4oEVGQhZg6r4IQGV
Screen Recording of the issue: https://drive.google.com/file/d/12zWMujEl-gb4VyD0zq5uOvMYKeZ_8keu/view?usp=sharingRegards,
Vaarun Sinha
Code:exports = function(arg){

    let collection = context.services.get("mongodb-atlas").db("store").collection("products");

  return collection.findOne({_id:BSON.ObjectId(arg)})};

[Assistant]
Text:Did you find a resolution? Anyone from Mongo can chime in?
Code:

[Assistant]
Text:I’m having the same type of issue. But im trying something like this in an API:
Code:const value = JSON.stringify(uid)
const palette = await db.collection("users").find({ _id: ObjectId(value) }).toArray()

[Assistant]
Text:When I click on the card and go to the product page it works fine, but when i reload the product page it returns an errorwhen you reload, your page has only what you include in your URL and the things you have saved in the Browser’s cache.In both cases, if you do not properly code what properties will be available to the page and how the page handles them are both left to the developer of the frontend.In your case, it is clear that the page does not do that inside the products page, but relies on the product card to pass the id to it. since the id is not in the form MongoDB expects (most possibly it is just null or undefined) then you get that error.
Code:

[Assistant]
Text:I’m having the same type of issue. But im trying something like this in an API:Your issue has the same error for a different reason. JSON.stringify() will give an error if its arguments is not an object. You don’t seem to get an error in that step so uid is an object, and your value will be something like this:see, the single quotes are surrounding those inner double quotes. you can now see why ObjectId() gave an error. value does not have a proper shape.you have two options now depending on what uid holds.
Code:JSON.stringify()objectuidvalue='{"id":"someIdValue"}'
ObjectId()valueuidconst value = uid.id // directly use the id field if it is a proper formatted string
or
.....find( { _id : uid.id } ) // directly use the id field if it is a proper object id.

[Assistant]
Text:I’m still battling this issue.  There’s something happening when the document _id is sent from the client to the server.  It’s no longer being read as a string even though its typeof value equals string.
Code:_idtypeofstring