I have a table videos with documents that look like this:
{
"title":"Video Name",
"description": "A description",
"slug":"video-name",
"studio": {
"name": "Studio Name",
"uid":"zyxwvut"
},
"uid":"abcdefghijkl"
}
I'm trying to grab related videos by the current video's studio by getting all videos with the studio.uid of zyxwvut, while also removing the ID of the requested video (uid of abcdefghijkl).
I've tried a few queries:
r.db('dev').table('videos').filter(function(video){ return video('studio')('uid').contains('zyxwvut').and(r.not(video('uid').eq("abcdefghijkl"))) })
with r.js:
r.db('dev').table('videos').filter(function(video){ return r.('(function (video) { return video.studio.uid == "zyxwvut"; })').and(r.not(video('uid').eq("abcdefghijkl"))) })
Am I going about this all wrong, or is it not possible?
You were close. You can do:
r.db('dev').table('videos').filter(function(video) {
return video("studio")("uid").eq("zyxwvut")
})
Related
I created a Mongoose schema that allowed me to save a whole JSON object which contains an array of objects (those objects have the _ids I want), but when I try to get one user from router.get express (I'm using findById), it returns null, when I do a get petition getting the whole data (using find() method) it looks like this:
thanks to all of you, English is not my first language, sorry for whatever grammar mistake that I could've made
[
{
"_id": "6384db62827c2f0816944734",
"arrayData": [
{
"description": "KEYCAPS",
"price": "$99.00",
"img": "link,of.the.image",
"_id": "6384db62827c2f0816944735"
},
{
"description": "KEYCAPS",
"price": "$99.00",
"img": "link,of.the.image2",
"_id": "7454db62827c2f0816912345"
}
]
}
]
I've tried other ways of getting the ids, to be honest I've been coding just for a couple of months, I'm a little shy of showing it but I believe this is the code I need to change
router.get('/users/:id', (req, res) => {
const { id } = req.params;
userSchema
.findById(id)
.then((data) => {res.json(data)})
.catch((err) => res.json({message: err}))
})
by the way my request.http enter image description here
enter image description here
i have an array of nested objects that give each user a permission.
const UserList = [{
0: {
users: {
"email": "user1#gmail.com"
},
permission: {
"id": 1,
"access": "Edit"
}
},
1: {
users: {
"email": "user2#gmail.com"
},
permission: {
"id": 2,
"access": "Read Only"
}
},
2: {
users: {
"email": "user3#gmail.com"
},
permission: {
"id": 1,
"access": "Edit"
}
},
}]
My problem: I want to be able to match a email string to the email in the object and then grab object with the access "read only'. This is all to disable a button. So if the current user's email matches one in the object and the access equals "read only" then pull it out. Im not sure if i want to create a function/prop for this condition but the disable button is in another file.
So lets say this is my email
const myEmail = user2#gmail.com. How do i compare it to UserList and create that condition above. Then transfer it to a button in another file <button disabled={solution goes here}></button>
Edit: I want to find the object that has the current users email, then if that object's access = read only, then disable.
Maybe a .include(myEmail)? Not sure
Thanks for your help!
You can use Object.values(UserList) to get an array with just the values (the user object in this case). Then you can use that list to do your rendering (seems you are using react), so you can just map over the list, and then use the information to check whether a value is `Read Only" etc.
in your HTML, that looks something like:
<button disabled={userObj.permissions.access !== "Read Only"}>
I am not quite following the question about matching email strings.
I'm currently building a website on Wix, and have come across a problem I can't think myself out of. Neither Wix support or the Wix Velo Forum have been able to help me out.
I have a repeater that is connected to the Stores/Products collection, and in the Stores/Products collection there's a collection field that contains additional info sections on the product. I have three info section; Tempo, Genre and Tags. Each contains a description.
It looks like this:
[
{
"title": "Tempo",
"description": "<p>142 BPM</p>\n"
},
{
"title": "Genre",
"description": "<p>Jazz</p>\n"
},
{
"title": "Tags",
"description": "<p>Frank Ocean, Travis Scott</p>\n"
}
]
I have figured out how to pull the individual objects with this code:
export function audioRepeater_itemReady($item, itemData, index) {
let product = $item('#dataset3').getCurrentItem(itemData._id)
let ArrayAdditionalInfo = []
ArrayAdditionalInfo = product.additionalInfoSections
ArrayAdditionalInfo.forEach((element) => {
console.log(element.title)
console.log(element.description)
})
But I want it to be able to figure out if eg. the Title === "Genre", then it will show the description from that array, like this:
{
// if equal to this:
"title": "Genre",
// show me this
"description": "<p>Jazz</p>\n"
},
The whole plan with this is to show the description output in a text element that I can implement in the repeater.
I have tried with if statements, but I just can't put it together myself. If this is confusing I'll gladly elaborate.
Thank you in advance.
I'm not a 100% sure if I understood the question correctly, but if you want to show all titles, and, conditionally the description if the title is Genre, you could just use a Ternary:
let data = [{
"title": "Tempo",
"description": "142 BPM\n"
},{
"title": "Genre",
"description": "Jazz\n"
},{
"title": "Tags",
"description": "Frank Ocean, Travis Scott\n"
}];
data.forEach(e => $("#products").append(
`<p>Title: ${e.title}${
e.title === "Genre"
? "<br>description: " + e.description
: ""
}</p>`
));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="products">
</div>
I think your issue related to handler. You use repeaters onItemReady handler, which is not the best option for your case. It calls for each row in repeater. Instead of this I recommend to use dataset's onReady
$w("#dataset3").onReady( () => {
console.log("The dataset is ready");
$w("#audioRepeater").getItems(0, 20).then( (result) => {
let items = result.items;
items.forEach((element) => {
if (element.title === 'Genre') {
doWhatDoYouWant(element)
}
})
} ).catch( (err) => {
let errMsg = err.message;
let errCode = err.code;
} );
} );
Please take into consideration that this block should be inserted into $w.onReady
I am trying to add an item to a list. The list has 2 columns in it: Title and recipientId (it is of type Person or Group). Now I am using
https:<site url>/_api/web/Lists/getbytitle('list name'>)/items
to create the list. Unfortunately I am unable to figure out what value I should be giving to recipientId (some blogs here mentioned we have to provide the user id. If that is right, how do I get that id or what exactly I should give there for the user to get added there?) This is the json I am using in post man to create the item:
{ "__metadata":
{
"type": "SP.Data.List3ListItem"
},
"Title": "Teams incorporate feedback"
}
If your column allow mutiple value:
{
"__metadata":{
"type":"SP.Data.TestListItem"//change this value to yours
},
"Title":"Test",
"supervisorId":{
"results":[25,26]//user ids
}
}
If your column only allow single value:
{
"__metadata":{
"type":"SP.Data.TestListItem"
},
"Title":"Test",
"supervisorId":5
}
Hopefully this might save someone's time,
so to add a value for a column of type "person or Group"(recipientId in my case). Firstly, we need to have the site users id that you can get from REST API https://<site_url>/sites/<site_name>/_api/web/siteusers. Once you have the ID, you can add it as value for "UsernameId" key value
{ "__metadata":
{
"type": "SP.Data.List3ListItem"
},
"Title": "Varun",
"UsernameId":13
}
this will add the corresponding user name to the column of type "person or Group"(recipientId in my case).
I use Meteor to query a mongo collection. It has for example the following entry:
{
"_id": "uCfwxKXyZygcWQeiS",
"gameType": "foobar",
"state": "starting",
"hidden": {
"correctAnswer": "secret",
"someOtherStuff": "foobar"
},
"personal": {
"Y73uBhuDq2Bhk4d8W": {
"givenAnswer": "another secret",
},
"hQphob8s92gbEMXbY": {
"givenAnswer": "i have no clue"
}
}
}
What I am trying to do now is:
don't return the values behind "hidden"
from the "personal" embedded document only return the values for the asking user
In code it would look something like this:
Meteor.publish('game', function() {
this.related(function(user) {
var fields = {};
fields.hidden = 0;
fields.personal = 0;
fields['personal.' + this.userId] = 1;
return Games.find({}, {fields: fields});
}, Meteor.users.find(this.userId, {fields: {'profile.gameId': 1}}));
}
Obviously this won't work, because MongoDB won't allow mixed includes and excludes. On the other hand, I cannot switch to "specify only the included fields", because they can vary from gameType to gameType and it would become a large list.
I really hope that you can help me out of this. What can I do to solve the problem?
Typical example of where to use the directly controlled publication features (the this.added/removed/changed methods).
See the second example block a bit down the page at http://docs.meteor.com/api/pubsub.html#Meteor-publish.
With this pattern you get complete control of when and what to publish.