Hi
i’m trying to input a text in and run a query with it. if the result is not present in the database, then i want to add it as a new item.
Hi,
You can add .eq to your wixData.query to do so.
import wixData from 'wix-data';
//...
export function triggerButton_click(){
let textInput = $w("#textInput").value;
wixData.query("Database").eq("property", textInput).find().then((Res)=>{
if(Res.items.length === 0){
let toInset = {
"property": textInput
};
wixData.insert("Database", toInsert).catch((err)=>{
console.log(err);
});
}
});
}
Hi
thank you very much.
I would like to take it a little bit further and query two fields
i want to query the database “APARTMENT-CLIENT–NAME” and add a new item if either one of “apartmentName” and “title” is different.
thanks a lot
wixData.query('APARTMENT-NAME')
.eq('title', $w('#dropdown1').value)
.find() // Run the query
.then(res => {
// Set the table data to be the results of the query
let firstItem = res.items[0];
let textInput = $w("#input9").value;
wixData.query("APARTMENT-CLIENT--NAME")
.eq("title", textInput)
.find()
.then((Res) => {
if (Res.items.length === 0) {
let toInsert2 = {
"apartmentName": firstItem,
"title": textInput
};
wixData.insert("APARTMENT-CLIENT--NAME", toInsert2)
.then((results) => {
$w('#input9').value = null;
$w('#dropdown1').value = null;
})
.catch((err) => {
let errorMsg = err;
});
}
});
}
);
Hi again,
It look like you want to create an apartment booking system…
① Choose an apartment website visitor want
② Book the apartment
Do I guess right?
Heson
hi Heson ,
not quite. this is for uploading images for each client.
but first, I want to add the clients name to the database if its not already there.
i have connected the clients name and Apartment Name databases with reference fields.
It looks great : )
Hi Heson Li,
Good day!
how can I filter my database by owner ID (_owner).
I have a code but it’s not working. see below
$w.onReady(() => {
wixData.query("regdog")
.eq("Owner", "_owner")
.find()
.then((results) => {
$w('#repeater1').data = results.items;
})
.catch((err) => {
console.log(err);
});
});
And I connect my repeater into the database.
I’m new in this kind of stuff so I’m kinda struggling how to write my code.
Thank you,
Geo
Hi Geo,
I have a question
If you want to have a filter page on load, why don’t you just setting in your’s dataset manager setting to have a filter ?
Is that possible?
I think Wix database don’t have a filter to display on a repeater yet.
So I will not connect repeater into my repeater?
Hi again,
I have read your code one more time.
The question may like that do you want to create a repeater, which show data from members do ?
Yes!
I want to display into the repeater the the data member inputs into my website.
it’s for the service dog registry website, If the customer register multiple dogs, all the dog the member entered will display on a repeater.
Thank you,
Geo
Hi Geo,
The inspire below may give you some help,
I guess you know how to create database & get data to database for your member’s action.
The solution is that
Setting your database premission like below,
“Who can update content from this collection”
Based on do you want to let your member can change the data inside database.
After setting correct permission, you just need to connect your repeater to dataset and no need to have extra code or filter for finding specific member’s action.
Remark,
Although there are no limit code or filter in your page, dataset may follow the permission of your database. Therefore, the most important may be “Who can read content from this collection”
It like creating a member profile page. Although the profile page connect to member database, site member author only can get their own data
Hope useful. Good luck,
Heson
Hi Heson Li,
I think it will not work, cause when the repeater connects into the database it only reads the _id, so it only display one item cause you can only have one id per data.
Thank you for the suggestion, so it should be done by code, filter the database by _owner ID (_owner) onReady.
Geo