Can we retrive data of two tables in nodejs with mongoose [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am working one project there is some relational concept so i want to retrieve data from two different tables in same query , can i do this ? i am following below link but i am not getting exact that i wants.
Mongoose/mongoDB query joins.. but I come from a sql background
I have also review this links
https://start.jcolemorrison.com/mongodb-joins-with-mongoosejs/
I have review this mongoose links, here i am getting something positive.
http://mongoosejs.com/docs/populate.html
What i have done so far is like below:
Create Models for project and project_category and try to get all project with category details. I have update my code at below link to review :
https://www.protectedtext.com/rushabhcode

mongooses have populate in built function to join two table
in schema just add ref for linking table
suppose you want to join two table
table 1 :User
table 2 :posts
in posts schema add
posted_by: {type: Schema.Types.ObjectId, ref: 'User', required: true},
and the time of query just add populate
suppose
postModel.find({}).populate({path:'posted_by'}).exec(function(err,response){
})
this will help you get all post value with user details who has posted

Related

How can I request the url for the top tweet of a hashtag using node.js? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am attempting to make a Discord bot that will post the top tweet of a hashtag when requested however I cannot figure out how to do this. I cant find anything for searching tweets of a hashtag in the Twitter API. How can I achieve this? Alternate solutions are welcome but I need it to be a Discord bot. Thanks!
Did you look at the search API documentation? There's an example for a hashtag right there:
Standalone operators can be used alone or together with any other
operators (including those that require conjunction).
For example, the following query will work because it uses the
#hashtag operator, which is standalone:
#twitterapiv2
You will need to do some work in your code to decide what constitutes "the top tweet" - do you mean the most recent Tweet, the Tweet with most likes, the most retweets, etc - you will have to check the metrics on the Tweet objects to decide which Tweet is "top" in your definition, there's nothing built-in to the API that returns just the "top" Tweet, unless you just want the most recent result.
Judging by the this api reference they have a custom query thing going on. I'm sure you should be able to use their query options to get the data you want

In single page application how to reload api without reloading page when new data is entered in VueJs [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I actually have made a single page application for school management where there are multiple records of the student and when data is entered , data are changed in database but doesn't affect other component until I reload the page.
I have used API to fetch the data from database.How to solve this problem in VueJs.
Suppoue you have the students data on dataStudent:[] now you entered a new data on same table where from dataStudent:[] came, when you enter data to database subbpouse you have data on formValue:{} which is object and all the data from formValue added on database now after successfully added you have to push these data to the array,
like: dataStudent.push(formValue);

Generate fake data that don't change [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I'm creating a temporary GraphQL backend, that should serve mocked data.
E.g. I need ~500 objects of the model Person (with firstName, lastName, email, country, etc), where the properties shouldn't change on each request.
Is there any library where it's possible to get fake data always created in the same order?
You can easily create your custom JSON with https://next.json-generator.com/ which allows using internal scripts for data generation
Here is an example of generating a list of names: https://next.json-generator.com/Vk95XL5mv
Not sure if this is exactly what you want, but I discovered this site: https://crudpi.io/ this weekend, you can mock some data in a JSON file and use it for your API. I guess that it's limited to 100 objects or something, but if you need the same data, you can copy it 5 times I guess. Hope it helps!
I wish that I could write this as a comment but I don't have enough reputation yet.
Here's an API. https://uinames.com/api/?amount=500
You should easily just create a script, add the data you got from this to a temp-database.
You can use a generator like https://randomuser.me/
Make a loop to create your object then keep the result in a file to ensure the data will be the same.
You can get an exemple here : https://gist.github.com/Yexan/cb8b79390e01272a4912fb4d6773ee1a
I used https://randomuser.me/api/?results=500

Creating a room with Firebase for a web app [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Im currently building a web app based in firebase and want users the ability to create and join game rooms. Currently i am having an issue trying to figure out how to create the room where others can join. I was wondering if anyone can help me get started on this issue. Just an FYI each user who will be creating and joining the room will have their own account with unique ID if that matters
Firebase doesn't have any concept of rooms. There are parent and child nodes which are code wise handled through key: value pairs, very similar to a Dictionary.
There are also no users in Firebase either, other than the user id's (uid) and associated data that are created when new user is created in Firebase and stored internally on the server. That data is used for authentication. If other data needs to be stored about a user, a name perhaps, it's done within the database itself.
Keeping it simple, let's say we want to store information about users and rooms.
users
uid_0
name: "Bill"
uid_1
name: "Ted"
uid_27
name: "The Doctor"
The uid's are the ones that are created when a new user creates an account in Firebase. Your app will collect the uid that Firebase provides and write it and any other user data to the users node; in this case the users name.
Then the rooms
rooms
room_0
room_name: "Phone Booth"
description: "Time travelling in style; Excellent!"
uid_0: true
uid_1: true
room_1
room_name: "Tardis"
description: "It's bigger on the inside"
uid_27: true
In this case room_0, the Phone Booth, has both Bill and Ted in it and room_1 has The Doctor in it.
This is not the only way to structure the data and your structure may vary from this a lot, but it's a place to start.
Note: key names should almost always be created with push(). I used room_0 etc as a placeholder. Best practice is to disassociate main parent key names from the data it contains. i.e. don't hard code key names with something like an email address - that's bad news.

PHP Get Values from a URL using GET[] [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to develop products filters for an online store I am working on. An example of what I mean is http://www.riverisland.com/men/just-arrived. I have managed to get a JavaScript to populate the URL when the sizes are clicked on but failed to get them remove value from URL when unchecked.
My main question here is this. Assuming I have my URL as:
http://127.0.0.1/shop/dresses/?s=1&s=2&s=3
How do I get my PHP to extract the values from the URL?
How do I format a SQL query to search the values gotten from the URL using any sample query?
An easier solution is this.
Format your URL like http://127.0.0.1/shop/dresses/?s=1,2,3 as suggested by #Andrey.Popov. Then do the below.
if(isset($_GET['s']) && !empty($_GET['s']))
{
$e = sanitizeFunction($_GET['s']);
$d=explode(',',$e);
}
$d now has all your $_GET['s'] values.
That's the easier way I have figured out and it works!
In order to benefit from $_GET and other superglobals you have to follow the rules explained at Variables From External Sources. Since you've chosen to have several parameters with the same name and they do not contain properly paired square brackets you're basically on your own. The manual steps you must reproduce include:
Extract the raw query string from $_SERVER['QUERY_STRING'], e.g.:
$query_string = filter_input(INPUT_SERVER, 'QUERY_STRING');
Parse out the string. As far as I know, there aren't built-in functions that do exactly this so I'd either google for a good third-party library or write a simple parser with regular expressions or good old explode().
Decode the URL-encoded values with urldecode()

Categories