Trouble with variable in Postman POST request - mongodb

I am very new to coding, so my apologies if I use the wrong terms or am unclear. I have a list of 400+ words I need to be able to enter into my database. I found this collection to loop through my data and post it to the database. I am able to mostly get it to work, except for this one section (the meanings section) where it's an array of objects. If it makes a difference, this is for a React project and using MongoDB for the database.
Each word looks like this:
{
"text": "happy",
"traits": [
"wordlist100"
],
"meanings": [
{
"meaning": "happy",
"category": "default"
}
],
"approved": true,
"createdby": "60dcd7ba69b1e52ac8138051",
"approvedBy": "60dcd7ba69b1e52ac8138051",
"lastUserEdit": "60dcd7ba69b1e52ac8138051",
"blocked": false
}
Where each word can have multiple traits and multiple meanings.
I have all the words in a JSON file, and am running it through Postman using the collection linked above. This is the body of my request in Postman:
{
"text": "{{text}}",
"traits": [
"{{traits}}"
],
"meanings": [
{
"meaning": "{{meaning}}",
"category": "{{category}}"
}
],
"approved": true,
"createdby": "60dcd7ba69b1e52ac8138051",
"approvedBy": "60dcd7ba69b1e52ac8138051",
"lastUserEdit": "60dcd7ba69b1e52ac8138051",
"blocked": false
}
Using this, everything comes through correctly in my database except for the meaning and category of a word. This is what shows up in MongoDB:
{
"_id": {"$oid": "6121bd6addff936ba4eb84bf"},
"traits": [
"wordlist100"
],
"text": "happy",
"meanings": [
{
"_id": {"$oid": "6121bd6addff936ba4eb84c0"},
"meaning": "{{meaning}}",
"category": "{{category}}"
}
],
"approved": true,
"createdBy": {"$oid": "60dcd7ba69b1e52ac8138051"},
"approvedBy": {"$oid": "60dcd7ba69b1e52ac8138051"},
"lastUserEdit": {"$oid": "60dcd7ba69b1e52ac8138051"},
"blocked": false,
"createdAt": {"$date": "2021-08-22T02:58:50.679Z"},
"updatedAt": {"$date": "2021-08-22T02:58:50.679Z"},
"__v": 0
}
What am I doing wrong with the meanings section of the word? I tried playing around with several combinations of brackets and such for how to set up the meanings part.
I did try:
"meanings": [
"{{meanings}}"
]
...but that didn't work at all. Most of what I tried created an error that stopped the collection from running at all (it was probably bad syntax, as I said, I'm really new). This is the only arrangement that seems to get me close to right. Any help would be greatly appreciated.
Thanks!!
Attaching pics of the Postman code and created MongoDB document if it's easier for any of you to look at it with that formatting:
Image of Postman code
Image of MongoDB document created

So I feel foolish and this just shows how new I am to all of this. When I posted this question, all I had done was to try copying the style of what I saw in the body text of the example I found (linked in my question), but didn't do anything with actually defining variables or touching the pre-request script because I didn't realize that was a separate step. So basically, I just got lucky that it was smart enough to figure out the other values without me defining them as variables.
If anyone is reading this later, here's 3 pages of documentation I used to help me figure out my errors: Using Variables, Importing Data Files, and Scripting in Postman.
From reading those, I added the following code in the pre-request script:
let meanings = pm.iterationData.get("meanings");
pm.variables.set("meaning", meanings[0].meaning);
pm.variables.set("category", meanings[0].category);
I also set "meaning" and "category" as named variables with no initial value in the collection.
Image of adding variables to the Postman collection
One caveat I should note is that I'm not certain how well this will work once I start entering stuff with more than one trait or more than one meaning, because I haven't tested those parts yet. I suspect I still need to tweak things to make it work under those instances. But it is working in the examples I have with just one trait and one object in the meanings array.

Related

"Operation passed in cannot be an array" compass error - but JSON isn't an array

Trying to import simple data (see below), gets me an error "Operation passed in cannot be an array" in Compass 1.29.6
This error makes no sense to me, as the outer object is not an array. Sure, the first object contains an array, but how is this not importable, since it is valid JSON? What is it expecting?
I have checked the documentation for Compass, perused other similar errors, no answers are obvious or relevant enough to help me.
{
"Name": "root",
"ID": 0,
"Children": [{
"Name": "Chocolates",
"ID": 1,
"ParentID": 0
}]
}
I am a bit late but try to wrap your object into array like
[{
"Name": "root",
"ID": 0,
"Children": [{
"Name": "Chocolates",
"ID": 1,
"ParentID": 0
}]
}]
it will work
MongoDB Compass accepts documents in unformatted json structure, I used http://json.dylansweb.com/ to un-format the json and it worked fine in Compass.
This has been an open issue on github for over 4 years now with no real solution from compass. Every suggestion is pretty hacky and the only real solutions seem to be to not use Compass https://github.com/mongo-express/mongo-express/issues/433

How to get from JSON to Mutable Data

I'm working on a Flutter "Collections" app where I want a user to be able to define a schema for their list, then create several items that conform to that schema.
{
"name": "My Book Collection",
"schema": [
{
"id": "uuid-title",
"type": "text",
"name": "Title",
"unique": true
},
{
"id": "uuid-pages",
"type": "number",
"name": "Pages",
"min": 0,
"max": null,
"format": "int"
}
],
"items": {
"abc-123": {
"uuid-title": "The Hobbit",
"uuid-pages": 304
},
"def-456": {
"uuid-title": "Harry Potter and the Philosopher's Stone",
"uuid-pages": 223
}
}
}
What strategies can I use to update Specific Items or Schema Items, preferable immutably? I'm thinking I can make a Collection which has a List<SchemaItem> and Map<String, CollectionItem>. I think I can use a Provider or ProxyProvider to provide the List<SchemaItem> and a "Selected" CollectionItem to downstream widgets.
What strategies to I use to update items:
Is it enough to implement a CollectionItem.copyWith() function with some ChangeNotifier?
Do I need to go higher, with a Collection.updateItem(id: "abc-123", { "uuid-pages": 365 }) and wait for a Stream somewhere to provide an updated object?
Do I jump all the way to the top with a Service? CollectionService.selectedCollection.updateItem(id: "abc-123", { "uuid-pages": 365 }) and wait for a sqflite or Firebase update to trigger a rebuild?
I'm open to any starting points. All the tutorials, guides, and videos I've seen work with very simple data. Counters (Ints), ToDos (Strings & Bools), Pizza Toppings (List), but nothing with these nested maps. Do I just need to spend more time getting comfortable with OOP?
Finally, would I be crazy to work with the data as maps or should I definitely be converting them to Classes?
just activate the robo pojo generator in your android studio and past this json schema and get the corresponding model class and use it as you want

Removing Key:Value Pairs From Mongodb

I would like to remove all key/value pairs where the key is url from all documents inside a mongodb collection.
I've been agonising over this all weekend and have only managed to partially solve it using $unset, but I'm struggling to access all items particularly key/values inside objects in arrayKey and also do it in one query/function (if possible).
This is generally how each document looks. There sometimes may be more objects in the arrayKey, but other than that they're pretty similar:
{
"keyOne": "String",
"keyTwo": 7,
"keyThree": {
"subKeyOne": "String",
"url": "String"
},
"arrayKey": [
{
"arrayKeyOne":"String",
"url": "String"
},
{
"arrayKeyOne":"String",
"url": "String"
}
],
"url":"String"
}
Any help would be greatly appreciated. I'm still new to programming and mongodb so the documentation is a bit dense for a beginner.
Thanks :)

GET Values from a custom field via JIRA REST API

I would like to GET all drop down options for a custom field. For system fields, I use the following URI:
http://localhost:8080/rest/api/2/project/XXXX/components
(for components, versons, etc. Basically system fields), so I tried the following for a custom field
http://localhost:8080/rest/api/2/project/XXXX/customfield_10000
and got a 404 error. I'm not sure what I'm doing wrong as I've been googling for the past 19 hours. The best I search result I got was the following documentation: JIRA Developers Documentation
Please assist, I'm not sure What I'm missing
You can get that information either from the createmeta or editmeta REST resources.
Use editmeta if you want to retrieve the available options when editing a specific issue. E.g.
GET /rest/api/2/issue/TEST-123/editmeta
Use createmeta when you want to retrieve the options for a project in combination with an issue type. E.g.
GET /rest/api/2/issue/createmeta?projectKeys=MYPROJ&issuetypeNames=Bug&expand=projects.issuetypes.fields
The customfields with options will be returned like this:
"customfield_12345": {
"schema": {
"type": "string",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:select",
"customId": 12345
},
"name": "MySelectList",
"allowedValues": [
{
"self": "http://jira.url/rest/api/2/customFieldOption/14387",
"value": "Green",
"id": "14387"
},
{
"self": "http://jira.url/rest/api/2/customFieldOption/14384",
"value": "Blue",
"id": "14384"
}
]
}

MongoDB Storing User Files

I've been trying to become familiar with using MongoDB, particularly GridFS (which is implemented through the client). In a project I'm playing around with, I have users with corresponding locations, followed by corresponding data, but it is currently just stored on a filesystem which will ultimately lead to problems.
So an example data structure I have now is:
./(userId)/images/img1.png
./(userId)/data/sensor1/sensorOutput1.data
./(userId)/data/sensor1/sensorOutput2.data
./(userId)/data/sensor2/sensorOutput1.data
./(userId)/data/sensor2/sensorOutput2.data
So, in looking at GridFS, I see that you can pass attribute/values to be associated with the meta-data for each file. Looking at this setup and after reading tutorials on MongoDB, I thought of this approach:
Have one database with multiple collections (such as data or images just to separate some of the data). Then in each of the collections, have attributes for each document such as:
Under image collection:
{
"userId": 5,
"path": "",
"filename":"img1.png"
...
}
or
Under data collection:
{
"userId": 5,
"path": "sensor1",
"filename": "sensorOutput1.data"
...
}
Alternatively, I could just have a collection, and for the sake of this example, I'll call "Everything"
{
"userId": 5,
"path": "images/",
"filename": "img1.png"
...
}
{
"userId": 5,
"path": "data/sensor1/",
"filename": "sensorOutput1.data"
...
}
{
"userId": 5,
"path": "data/sensor2/",
"filename": "sensorOutput1.data"
...
}
Do either of these solutions seem reasonable? Would I then create an index on the "path" attribute? I've seen examples for adding files to MongoDB just haven't found one with how to structure user files.
Thanks!