Dataset 'ne' filter not working

Hi, I have a table linked to a dataset. The dataset contains user info. I first filter the dataset to look for the record matching the currently logged in user in order to grab the full name. Then I refilter the dataset to exclude the currently logged in user. But the function returns the full database and doesn’t exclude the record. The ‘ne’ filter doesn’t seem to be doing its job. Here is the code.

$w ( "#datUser" ). setFilter (  wixData . filter () 
    . eq ( "_id" ,  userId ) 
) 
. then ( () => { 
    
    // Form the full name of the current user 
    userName  =  $w ( "#datUser" ). getCurrentItem ()[ "firstName" ] +  " "  +  $w ( "#datUser" ). getCurrentItem ()[ "lastName" ]; 

    // Let's filter this dataset so it excludes the currently logged in user 
    $w ( "#datUser" ). setFilter (  wixData . filter () 
        . ne ( "_id" ,  userId ) 
    ) 
    . then ( () => { 
        console . log ( $w ( "#datUser" ). getTotalCount ());   // It returns the full database 
    } ) 
    . **catch** ( ( err ) => { 
        console . log ( err ); 
    } ); 
} ) 
. **catch** ( ( err ) => { 
    console . log ( err ); 
} ); 

Can someone tell me why the ‘ne’ filter doesn’t seem to be working?

P.S. I tried filterng the dataset manually and the same thing happens. If I use ‘eq’ it works fine, but not with ‘ne’.

Try:

 $w("#datUser").onReady(() => {
    $w("#datUser").setFilter( wixData.filter()
        .eq("_id", userId)
)
    .then( () => {
        userName = $w("#datUser").getCurrentItem()["firstName"] + " " + 		$w("#datUser").getCurrentItem().lastName;
        return $w("#datUser").setFilter( wixData.filter()
            .ne("_id", userId)
        )
})
        .then( () => {
            console.log($w("#datUser").getTotalCount());
        } )
        .catch( (err) => {
            console.log(err);
 //       } );
    } )
   //.catch( (err) => {
    //    console.log(err);
   // } );
    })

P.S and make sure that the _id in the datUser is equal to the userId.
If the datUser is connected to the privateMemeberData collection you won’t able to show other users unless the logged in user is an Admin.
If you wish to show data from the privateMemeberData to unauthorized members, don’t use a dataset but query the collection in the backend using {suppressAuth: true}

@jonatandor35 Hi and thanks for your help. Unfortunately, it still doesn’t work. If I use ‘eq’ it works wonderfully, but not with ‘ne’. Here’s the code:

wixData . query ( “Members/PrivateMembersData” )
.n e ( “_id” , userId )
. find ({ “suppressAuth” : true })
. then ( ( results ) =>
{
console . log (r esults . items . length ); // Returns 3, whereas it should be 2
} )
. catch ( ( error ) => {
let errorMsg = error . message ;
let code = error . code ;
} );

@internationalcovidsu As I said, if the site visitor is not an admin, you can’t display data of other members from the Members/PrivateMembersData, unless you run the query on the backend and supress the auth.

//Front end (page code)
import wixUsers from 'wix-users';
import {getOtherMembersInfo} from 'backend/data-queries.jsw';
queryMemebersInfo();

function queryMemebersInfo()
if(wixUsers.currentUser.loggedIn){
	getOtherMembersInfo()
	.then(res => {
		console.log(res.items.length);
	})
});
//backend/data-queries.jsw
import wixData from 'wix-data';
import wixUsersBackend from 'wix-users-backend';
export function getOtherMembersInfo(){
return wixData.query("Members/PrivateMembersData")
        .ne("_id", wixUsersBackend.currentUser.id) 
	.limit(1000)
        .find({"suppressAuth": true})
})

@jonatandor35 Thanks, I created the backend JSW and pasted the code there. I also pasted the front end code and tried it, but I get an empty set. :frowning:

@internationalcovidsu I don’t see a reason for that. I think the code I posted is supposed to work.
Try to debug your code, add conole.log() in different places and check it in the site monitoring tool maybe you’ll see an error somewhere.

@jonatandor35 Hi, I tried everything. No go. I still get all records back from the dataset, including the ID of the currently logged in user. The ‘ne’ clause is just not working.

@internationalcovidsu If the code I posted doesn’t work for you, you’ll have to make a research, debug your code, and find out where the problem is.