#Keeps saying cannot read properties of undefined
1 messages · Page 1 of 1 (latest)
What's your code?
for the first error: databases.listDocuments(collectionId, [
Query.equal('title', 'Avatar'), // Use Query.equal() for equal conditions
Query.select([
'Author',
'Title',
'Date_Time', // Change to camelCase or any valid variable name
'Email',
'Content',
'KeyPoints'
])
], {
limit: 10,
offset: 0,
orderField: 'createdAt', // Specify the field to be used for sorting
orderType: 'desc' // Specify the sorting order, 'desc' for descending, 'asc' for ascending
}).then(response => {
if (response.documents) {
response.documents.forEach(document => {
const author = document.Author;
const title = document.Title;
const dateTime = document['Date_Time']; // Use square brackets to access properties with hyphens
const email = document.Email;
const content = document.Content;
const keyPoints = document.KeyPoints;
console.log(author, title, dateTime, email, content, keyPoints);
});
} else {
console.log('No documents found');
}
});
2nd error: account.create(ID.unique(), ''', '', '')
.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
where is databases and account coming from?
Im sry i need to leave... i'll come back in abit
from: const databases = new Databases();
const account = new Account(client);
You're supposed to pass a client into Databases.
Also where did client come from?
We should focus on one problem at a time. Let's do account first. Perhaps there's something wrong with the import/export for account? What's your full code?
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('');
okay.
console.log('JavaScript file is loaded.');
var alerted = localStorage.getItem('alerted') || '';
if (alerted != 'yes') {
alert("This website is under development if there are any issues please email me at [email protected]");
localStorage.setItem('alerted','yes');
console.log("It worked")
}
else {
console.log("Already alerted");
}
const { Client, Databases, Query } = Appwrite;
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('');
const account = new Account(client);
// Register the user using the account.create function
account.create(ID.unique(), '', ', '')
.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
const databases = new Databases();
const collectionId = '';
databases.listDocuments(collectionId, [
Query.equal('title', 'Avatar'), // Use Query.equal() for equal conditions
Query.select([
'Author',
'Title',
'Date_Time',
'Email',
'Content',
'KeyPoints'
])
], {
limit: 10,
offset: 0,
orderField: 'createdAt',
orderType: 'desc'
}).then(response => {
if (response.documents) {
response.documents.forEach(document => {
const author = document.Author;
const title = document.Title;
const dateTime = document['Date_Time']; // Use square brackets to access properties with hyphens
const email = document.Email;
const content = document.Content;
const keyPoints = document.KeyPoints;
console.log(author, title, dateTime, email, content, keyPoints);
});
} else {
console.log('No documents found');
}
});
thats all the code for that javascript file
alr thx!!
This is all in the same file?
yep
Looks like you're missing an improvement for Account?
Im sry? I dont get it
Where's Account?
The properties?? I deleted them on purpoes when i sent them..
no
const account = new Account(client);
Where's that Account defined?
because it's not here:
const { Client, Databases, Query } = Appwrite;
oops... i must have copied the wrong part of that... i edited to client.account.create
is that not a function?
nope
Well.. you learn something new everyday.. Thanks for informing me!